File tree Expand file tree Collapse file tree 1 file changed +21
-23
lines changed Expand file tree Collapse file tree 1 file changed +21
-23
lines changed Original file line number Diff line number Diff line change 1
1
# Time: O(nlogn)
2
2
# Space: O(n)
3
3
4
- SELECT *
5
- FROM
6
- (SELECT t .team_id ,
7
- t .team_name ,
8
- IFNULL(SUM (m .points ), 0 ) AS num_points
9
- FROM TEAMS t
10
- LEFT JOIN
11
- (SELECT host_team AS team_id,
12
- CASE
13
- WHEN host_goals > guest_goals THEN 3
14
- WHEN host_goals = guest_goals THEN 1
15
- ELSE 0
16
- END AS points
17
- FROM Matches
18
- UNION ALL SELECT guest_team AS team_id,
19
- CASE
20
- WHEN host_goals < guest_goals THEN 3
21
- WHEN host_goals = guest_goals THEN 1
22
- ELSE 0
23
- END AS points
24
- FROM Matches) m
25
- ON t .team_id = m .team_id
26
- GROUP BY t .team_id ) r
4
+ SELECT t .team_id ,
5
+ t .team_name ,
6
+ IFNULL(SUM (m .points ), 0 ) AS num_points
7
+ FROM TEAMS t
8
+ LEFT JOIN
9
+ (SELECT host_team AS team_id,
10
+ CASE
11
+ WHEN host_goals > guest_goals THEN 3
12
+ WHEN host_goals = guest_goals THEN 1
13
+ ELSE 0
14
+ END AS points
15
+ FROM Matches
16
+ UNION ALL SELECT guest_team AS team_id,
17
+ CASE
18
+ WHEN host_goals < guest_goals THEN 3
19
+ WHEN host_goals = guest_goals THEN 1
20
+ ELSE 0
21
+ END AS points
22
+ FROM Matches) m
23
+ ON t .team_id = m .team_id
24
+ GROUP BY t .team_id
27
25
ORDER BY num_points DESC ,
28
26
team_id;
You can’t perform that action at this time.
0 commit comments