Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

SQL:obtendo o valor máximo de uma coluna e as outras colunas correspondentes


Use ROW_NUMBER() :
SELECT s.id,s.tag,s.version FROM (
    SELECT t.*,
           ROW_NUMBER() OVER(PARTITION BY t.id ORDER BY t.version DESC) as rnk
   FROM YourTable t) s
WHERE s.rnk = 1