Devendra Kumar

Devendra Kumar

  • NA
  • 500
  • 163.1k

Sql query for calculation

May 13 2018 10:04 AM
I have 4 tables
Purchase
Purchase Return
Sale
Sale Return
 
Data on purchase table
 
Data on purchase return table
 
Data on sale table
 
No data in sales return table
 
I want the sum of purchase price based on itemcode having same purchase price from all table
where pQty = Qty from purchase table
            PRQty = Qty from purchase return table and so on 
 
the calculation for
pQty of Itemcode =1  is 18 (10+8 from purchase table)
PRQty of Itemcode =1 is 3 (2+1 from purchase return table) and so on
-----------------------------------------------------------------------------------------------------------------------------
The final output 
 
The calculation for
closing qty of Itemcode 1 = 21 (sum of pQty- sum of PRQty - sum of SQty - sum of SRQty)
price of ItemCode 1 = 155 (
(sum of _PPrice- sum of _PRPrice - sum of _SPrice - sum of _SRPrice)
 
same calulation is applied in Itemcode 2
 
Please help me with the sql query 
 

Answers (3)