It’s not easy for me to do this unless you search for the same table at least twice to grab the maximum row, and then grab the value for that row. This table is quite large, so this is unacceptable.
This is what my table looks like:
SCORES ID ROUND SCORE 1 1 3 1 2 6 1 3 2 2 1 10 2 2 12 3 1 6
I need to return the score that each identifier received in the last round. That is, a line with max (round), but not a maximum score.
OUTPUT: ID ROUND SCORE 1 3 2 2 2 12 3 1 6
Now I have:
SELECT * FROM (SELECT id, round, CASE WHEN (MAX(round) OVER (PARTITION BY id)) = round THEN score ELSE NULL END score FROM SCORES where id in (1,2,3) ) scorevals WHERE scorevals.round is not null;
This works, but is pretty inefficient (I have to manually filter all these lines, when I just have to just not capture these lines in the first place.)
What can I do to get the correct values?
source share