How to find the differences between the values of a specific column based on a key?

Posted by Holicreature on Stack Overflow See other posts from Stack Overflow or by Holicreature
Published on 2010-05-29T11:45:04Z Indexed on 2010/05/29 11:52 UTC
Read the original article Hit count: 189

Filed under:

I've two tables as purchase_details and invoice_details

and i want to store the inventory/stock of each product from the data of these two tables.

structure of purchase_details.

'pid', 'int(10)'
'product_id', 'int(10)' 
'quantity', 'float(8,2)'
'amount', 'float(12,2)'
'expiry_date', 'date'

structure of purchase_details.

'invoice_id', 'int(10) unsigned'
'product_id', 'int(10) unsigned'
'quantity', 'float(10,2)'
'price', 'float(12,2)'

i want to calculate the total quantity of remaining stock (quantity of sum of products from purchase_details - quantity of sum of products from invoice_details).

Product_id is would be same for the two tables.

how can i proceed?

© Stack Overflow or respective owner

Related posts about mysql