Sum of Columns for a Record

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
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Sum of Columns for a Record

Post by Pyrite »

How can I get the SUM of all columns in a row ? No I don't mean get the SUM of one column for a bunch of rows either, the SQL SUM() Function is not what I need ( I don't think ). :roll:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Which db are you using?

Mac
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

MySQL, but I'd prefer an ANSI SQL method if possible.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

hmm...

Code: Select all

select field1+field2+field3+field4+.... as sum_of_all_columns from your_table where condition_here
=)
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

seems like i tried that ... hold on a sec..
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Ok, now that works. Swear it didn't before, but Weirdan must have blew his magic dust on my db. Thanks man!! ;)
Post Reply