URGENT HELP: SELECT STATEMENT????

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mapperkids
Forum Newbie
Posts: 15
Joined: Mon Feb 11, 2008 8:53 pm

URGENT HELP: SELECT STATEMENT????

Post by mapperkids »

Hi,

I have a select statement like below:


Add from month 1 to month 11
=========================
SELECT SUM(monthly_target_1) + SUM(monthly_target_2) + SUM(monthly_target_3) + SUM(monthly_target_4) + SUM(monthly_target_5) + SUM(monthly_target_6) + SUM(monthly_target_7) + SUM(monthly_target_8) + SUM(monthly_target_9) + SUM(monthly_target_10) + SUM(monthly_target_11) FROM target WHERE platform_code = 'B'

Problem: it return the value as 0, but if I take out one field, then it is working, it seems a limitation or something.


If I take out month 11, IT WORKS - add from month 1 to month 10
=========================================
SELECT SUM(monthly_target_1) + SUM(monthly_target_2) + SUM(monthly_target_3) + SUM(monthly_target_4) + SUM(monthly_target_5) + SUM(monthly_target_6) + SUM(monthly_target_7) + SUM(monthly_target_8) + SUM(monthly_target_9) + SUM(monthly_target_10) FROM target WHERE platform_code = 'B'


Is that any limitation on select statement only allow # of fields with SUM() function?

Is that a max. # of characters in one select statement?


How can I get around this?

Thanks
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: URGENT HELP: SELECT STATEMENT????

Post by jaoudestudios »

Try this...

Code: Select all

SELECT (SUM(monthly_target_1) + SUM(monthly_target_2) + SUM(monthly_target_3) + SUM(monthly_target_4) + SUM(monthly_target_5) + SUM(monthly_target_6) + SUM(monthly_target_7) + SUM(monthly_target_8) + SUM(monthly_target_9) + SUM(monthly_target_10) + SUM(monthly_target_11)) AS total FROM target WHERE platform_code = 'B'
Post Reply