V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  cocosing  ›  全部回复第 1 页 / 共 1 页
回复总数  3
2020-02-13 17:12:17 +08:00
回复了 mmdsun 创建的主题 MySQL 请问这个 SQL 怎么写
select emp_id, custom_id, sum
from (
select emp_id, custom_id, sum(money) as sum
from orders
group by emp_id, custom_id
) as o1
where (
select count(distinct o2.emp_id, o2.custom_id)
from (
select emp_id, custom_id, sum(money) as sum
from orders
group by emp_id, custom_id
) as o2
where o2.emp_id = o1.emp_id
and o2.sum > o1.sum
) < 10
group by emp_id, custom_id
order by emp_id, sum;
这个使用派生表进行然后取每个业务员的 top10 应该满足你的需求
@mmdsun
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3225 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 13:54 · PVG 21:54 · LAX 06:54 · JFK 09:54
Developed with CodeLauncher
♥ Do have faith in what you're doing.