Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had two tables as
table1 'sale' has column 'saleamount'
table2 'purchase' has column 'purchaseamount'

as
SQL
sale                         purchase
saleamount                   purchaseamount
40                           10
50                           20
60                           15


from above table,


SQL
40-10==30
50-20==30
60-15==45

i want to calculate total of the above difference(30+30+45=105)
Posted
Updated 15-May-15 21:51pm
v2

1 solution

You probably need to have a linking element between the two tables, that identifies the item you are buying and selling - otherwise you will need two tables for each item in your store, which is silly!

Buy - it's pretty trivial to get SQL to return the value from your tables:
SQL
SELECT (SELECT SUM(saleAmount) FROM sale) - (SELECT SUM(purchaseAmount) FROM purchase)
It's just that it is useless in the real world!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900