-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode1783.sql
More file actions
26 lines (25 loc) · 819 Bytes
/
LeetCode1783.sql
File metadata and controls
26 lines (25 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- UNION ALL各个赛事的player_id
select t.player_id, p.player_name, COUNT(*) as "grand_slams_count"
from (
select Wimbledon as "player_id"
from Championships
union all
select Fr_open as "player_id"
from Championships
union all
select US_open as "player_id"
from Championships
union all
select Au_open as "player_id"
from Championships
) t
left join Players p on t.player_id = p.player_id
group by
t.player_id;
-- 分组后在Select中直接统计
SELECT p.player_id, p.player_name, SUM(p.player_id = c.Wimbledon) + SUM(p.player_id = c.Fr_open) + SUM(p.player_id = c.US_open) + SUM(p.player_id = c.Au_open) grand_slams_count
FROM Championships c, Players p
GROUP BY
p.player_id
HAVING
grand_slams_count > 0;