Dette er også muligt uden underforespørgsel:
SELECT DISTINCT
id
,max(round) OVER (PARTITION BY id) AS round
,first_value(score) OVER (PARTITION BY id ORDER BY round DESC) AS score
FROM SCORES
WHERE id IN (1,2,3)
ORDER BY id;
Returnerer præcis det, du bad om.
Det afgørende punkt er, at DISTINCT
anvendes efter vinduesfunktioner.
SQL Fiddle.
Måske hurtigere, fordi den bruger det samme vindue to gange:
SELECT DISTINCT
id
,first_value(round) OVER (PARTITION BY id ORDER BY round DESC) AS round
,first_value(score) OVER (PARTITION BY id ORDER BY round DESC) AS score
FROM SCORES
WHERE id IN (1,2,3)
ORDER BY id;
Ellers gør du det samme.