2021年3月17日星期三

select the latest balance for each product based on store (SQL)

I'm trying to get latest balance for each product based on storeid . But I don know why get result duplicate stock name sasi.

Sql Query

select stockname, balance,updatedat,storename,s1.productid,s1.storeid  from stockmovement s1  inner join (select storeid, productid, max(updatedat) as maxdate              from stockmovement              group by storeid,productid) s2  on s2.storeid = s1.storeid and s2.maxdate = s1.updatedat  

enter image description here

https://stackoverflow.com/questions/66636014/select-the-latest-balance-for-each-product-based-on-store-sql March 15, 2021 at 06:14PM

没有评论:

发表评论