![]() |
| ||
| MySQL SUM Statemene 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; SELECT SUM(i.amount-p.amount) FROM income i, payments p; |
| ||
| Re: MySQL SUM Statemene Try SELECT SUM(i.amount) - SUM(p.amount) FROM income i, payments p |
| ||
| Re: MySQL SUM Statemene Quote:
Thanx but still doesn't work out |
| ||
| Re: MySQL SUM Statement 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 |
| All times are GMT -4. The time now is 11:20 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC