Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

SQL Sélectionnez les 2 premiers distincts

SELECT DISTINCT TOP 2 PartId, IdNumber, Length
FROM
(   SELECT PartId, IdNumber, Length, ROW_NUMBER() over(partition by IdNumber order by Length) Orden
    FROM [Ayuda]
) A
WHERE A.Orden = 1
ORDER BY Length