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

前端 未结 3 447
面向向阳花
面向向阳花 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 05:16

    You need to join into a Sub-query:

    SELECT i.ldPart, x.LastDate, i.inAbc
    FROM inventoryReport i
    INNER JOIN (Select ldPart, Max(ldDate) As LastDate FROM inventoryReport GROUP BY ldPart) x
    on i.ldPart = x.ldPart and i.ldDate = x.LastDate
    

提交回复
热议问题