sql - Sum a column from a table and subtract it to a summed column in another table -


i have 2 tables tblinventory , tblwithdrawal. tblinventory has productid tblwithdrawal.

grouping productid, how sum quantity in tblinventory , sum quantity in tblwithdrawal , subtract 1 can remaining or difference in quantity of each productid?

this came with, when run query, asks me input parameter wrong because want automatically go through table , operations on each productid.

select tblinventory.productid,        sum(tblinventroy.quantity) - sum(tblwithdrawals.quantity) [remaining] tblinventory   left join tblwithdrawals on tblinventory.productid = tblwithdrawals.productid  tblinventory.productid = tblwithdrawals.productid group tblinventory.productid 

thank you. need solve this!

don't user clause. , use inner join instead of left join


Comments