SQL conundrum, how to select latest date for part, but only 1 row per part (unique)

前端 未结 3 439
面向向阳花
面向向阳花 2021-01-13 04:47

I am trying to wrap my head around this one this morning.

I am trying to show inventory status for parts (for our products) and this query only becomes

3条回答
  •  天涯浪人
    2021-01-13 04:55

      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
    

提交回复
热议问题