Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SELECT SUM(`ServiceTaxAmount`) from `sale_has_enquiryitem` WHERE `ServiceTax`<>'NULL'




I had two tables as
table1 'sale' has column 'saleamount'
table2 'purchase' has column 'purchaseamount'

as
sale purchase
saleamount purchaseamount
40 10
50 20
60 15


from above table,


40-10==30
50-20==30
60-15==45
i want to calculate total of the above difference(30+30+45=105)
Posted
Comments
Maciej Los 16-May-15 6:54am    
Do not repost[^]!

See my answer to your previous example of this question: how to calculate difference of two columns[^]
 
Share this answer
 
XML
Hi,

You have 2 different ways to achieve your goal.

1) 

<pre lang="SQL">SELECT ((SELECT Sum(SaleAmount) FROM Sale) - (SELECT Sum(purchaseamount) FROM Purchase))


2) Above query will not look nice to read. So you can separate both the queries in variables and use them

SQL
Declare @SalesAmount money = (SELECT Sum(SaleAmount) FROM Sale)
Declare @PurchaseAmount money = (SELECT Sum(purchaseamount) FROM Purchase)

SELECT  @SalesAmount - @PurchaseAmount


Please let me know if yo have any concern or query or if you need any other help.

Thanks
Advay Pandya
 
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