Quantcast
Viewing all articles
Browse latest Browse all 2801

SQL Query Help

Hi,

 

Need some help on a sql query.

 

I have already got the data but want know an idea on how to arrange data.

 

Query result is like this

ItemCodeItemNameExpDateQtyExpiry
BAL0120Hit Minis Cocoa Cream 130g29/09/1640271
BAL0132Butter Leibniz 100g12/10/164971
BAL0143Zoo Jungle 100g28/04/164571
BAL0143Zoo Jungle 100g26/07/166022
BAL0204Choco Leibniz 125g07/10/1612451
BAL0205Choco Friend 100g30/04/1611
BAL0205Choco Friend 100g14/07/1636132
BAL0205Choco Friend 100g04/10/1660483

 

Want get the report like

Item CodeItem DescriptionExpiry 1QtyExpiry 2QtyExpiry 3QtyExpiry 4QtyTotal
BAL0120Hit Minis Cocoa Cream 130g29/09/1640274027
BAL0132Butter Leibniz 100g12/10/16497497
BAL0143Zoo Jungle 100g28/04/1645726/07/166021059
BAL0204Choco Leibniz 125g07/10/1612451245
BAL0205Choco Friend 100g30/04/16114/07/16361304/10/1660489662

 

 

Query is below

select ItemCode,ItemName,DistNumber,ExpDate,Qty,ROW_NUMBER() OVER(PARTITION BY ItemCode ORDER BY ItemCode,ExpDate) as Expiry from

(select T0.ItemCode, T2.ItemName,T0.DistNumber,T0.ExpDate,SUM(T1.Quantity) as Qty

from OBTN T0 left join OBTQ T1 on T0.ItemCode=T1.ItemCode and T0.SysNumber=T1.SysNumber left join OITM T2 on T0.ItemCode=T2.ItemCode

where T1.Quantity>0

group by T0.ItemCode,T2.itemName,T0.DistNumber,T0.ExpDate) s


Viewing all articles
Browse latest Browse all 2801

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>