explorer104
explorer104

Reputation: 57

Subtract total sum of a colum, From the total sum of a colum from another table

I'm wondering the subtraction total sum of amount_no column of table2 from total sum of amount_no table1.

   table1                           table2
   |amount_no |                     |amount_no|
   ------------                     -----------
   |230       |                     |100      |
   |500       |                     |50       |
   |700       |                     |40       |
   ------------                     ----------
   1430                             190
   ------------                     ----------
              (1430 - 190 = 1240)
SELECT ((SUM(amount_no) FROM table1) - (SELECT SUM(amount_no) FROM table2))

Upvotes: 0

Views: 53

Answers (2)

PPL
PPL

Reputation: 6555

Updated query:

SELECT (SELECT SUM(amount_no) FROM table1) - (SELECT SUM(amount_no) FROM table2)

Your code have missing some brackets.

Upvotes: 1

Echo
Echo

Reputation: 98

Use this:

SELECT (SELECT SUM(amount_no) FROM table1) - (SELECT SUM(amount_no) FROM table2)

Your code misses the select part and minor things.

Upvotes: 3

Related Questions