Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions mock3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Write your MySQL query statement below 1194
WITH CTE AS (
SELECT match_id, first_player AS player, first_score as score FROM Matches
UNION ALL
SELECT match_id, second_player AS player, second_score as score FROM Matches
)
SELECT group_id, player_id FROM(
SELECT group_id, player_id,
RANK() OVER(PARTITION BY group_id ORDER BY points DESC, player_id ASC) as rnk, points
FROM (
SELECT group_id, player_id, SUM(score) AS points
FROM CTE C LEFT JOIN Players P ON C.player = P.player_id
GROUP BY player, group_id) AS random) AS random2
WHERE rnk = 1;