I have a table in SQL like this. Now I want to find sum of score grouped by column ID & Name, and show just 2 highest sums for each ID as below, so how can I solve this? Thanks in advance.
CodePudding user response:
Can you try something like this:
Select ID, Name, Score From (
Select ID, Name, SUM(Score) score, row_number() over (partition by ID,Name order by SUM(Score) desc) rn
from Table
group by ID,Name) allScores
where rn > 2