SQL 1194 Tournament Winners

///
select group_id, player_id from (
select group_id, player_id, scores, row_number() over(partition by group_id order by scores desc, player_id) row_num
from
(select a.group_id, a.player_id, sum(b.score) scores from
Players a
join
(select
first_player as player,
sum(first_score) as score
from Matches
group by 1
union
select
second_player as player,
sum(second_score) as score
from Matches
group by 1) b
on
a.player_id = b.player
group by 1,2) ac
) abcdefg
where abcdefg.row_num = 1
;///
Why is this code wrong?

Comments (0)