Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Enigma SQL, come selezionare l'ultima data per la parte, ma solo 1 riga per parte (univoca)

  SELECT *
  FROM   (SELECT i.*,
      ROW_NUMBER() OVER(PARTITION BY ldPart ORDER BY ldDate DESC) r
      FROM   inventoryReport i
      WHERE  ldPart in ('ABC123', 'BFD21', 'AA123', etc)
         )
  WHERE  r = 1