cocosing's recent timeline updates
cocosing

cocosing

V2EX member #376518, joined on 2019-01-10 11:04:33 +08:00
Today's activity rank 23746
cocosing's recent replies
aWppYW5nemVlbkAxNjMuY29t 体验一下
Feb 13, 2020
Replied to a topic by 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
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1036 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 18:31 · PVG 02:31 · LAX 11:31 · JFK 14:31
♥ Do have faith in what you're doing.