cocosing 最近的时间轴更新
cocosing

cocosing

V2EX 第 376518 号会员,加入于 2019-01-10 11:04:33 +08:00
cocosing 最近回复了
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   ·   我们的愿景   ·   实用小工具   ·   2893 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 11ms · UTC 09:11 · PVG 17:11 · LAX 02:11 · JFK 05:11
Developed with CodeLauncher
♥ Do have faith in what you're doing.