Return one SQL row per product with price and latest date

前端 未结 6 1103
南旧
南旧 2021-01-24 03:35

I am not a SQL guy, I have used it in the past and rarely have an issue that cant be solved by google... however this time I need to ask the Community.

I have a database

6条回答
  •  长情又很酷
    2021-01-24 04:00

    Try this. by using row_number().

                 select * from 
                 (
                 select 
                 T.ProdNo, 
                 T.TransactionDate as 'LastPurchaseDate', 
                 T.Price,           
                 row_number() over (partition by ProdNo order by TransactionDate desc) as rnk
                 from Transactions T
                 )a
                 where rnk='1'
    

提交回复
热议问题