Ini juga dimungkinkan tanpa subquery:
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;
Mengembalikan persis seperti yang Anda minta.
Intinya adalah DISTINCT
diterapkan setelah fungsi jendela.
SQL Fiddle.
Mungkin lebih cepat karena menggunakan jendela yang sama dua kali:
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;
Jika tidak, lakukan hal yang sama.