•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 363,450 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,283 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 669 | Replies: 3
![]() |
•
•
Join Date: Jan 2006
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hi there,
Anyone to help me on sql code for SUM.
I need a query that gets the SUM of one table column and subtract it from the sum from another table column:
I tried this but it gave me wrong answer;
Anyone to help me on sql code for SUM.
I need a query that gets the SUM of one table column and subtract it from the sum from another table column:
I tried this but it gave me wrong answer;
SELECT SUM(i.amount-p.amount) FROM income i, payments p; Last edited by peter_budo : Apr 20th, 2008 at 6:36 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Dec 2007
Posts: 102
Reputation:
Rep Power: 1
Solved Threads: 10
Try
mysql Syntax (Toggle Plain Text)
SELECT SUM(i.amount) - SUM(p.amount) FROM income i, payments p
Last edited by mwasif : Apr 19th, 2008 at 3:15 pm.
•
•
Join Date: Jan 2006
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Try
mysql Syntax (Toggle Plain Text)
SELECT SUM(i.amount) - SUM(p.amount) FROM income i, payments p
Thanx but still doesn't work out
•
•
Join Date: Apr 2008
Posts: 248
Reputation:
Rep Power: 1
Solved Threads: 29
hi,
without where clause cross product of both tables will be computed, that is each row of income will be combined with each row of payments. To prevent this, you need a where clause like where i.fieldofincome = p.fieldofpayments, If you don't have such common fields you can't join both tables.
krs,
cliff
without where clause cross product of both tables will be computed, that is each row of income will be combined with each row of payments. To prevent this, you need a where clause like where i.fieldofincome = p.fieldofpayments, If you don't have such common fields you can't join both tables.
krs,
cliff
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
Other Threads in the MySQL Forum
- Previous Thread: uploading large txt file into phpmyadmin?
- Next Thread: command prompt view


Linear Mode