built-in functions in mySQL???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

built-in functions in mySQL???

Post by Joe »

Is there any built in functions in mySQL that allows you to "ADD" certain columns?. I have been trying to total a customers pricing so the admin can see the results though the administration panel with no luck.

Regards


Joe 8)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

MySQL has a SUM() function, see the docs for more info.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

OK thanks alot mark. Much appreciated!
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Another question on this topic actually. Is it possible to use

SELECT SUM(column1,column2,column3) FROM tablename

instead of:

SELECT SUM(column1) FROM tablename

Or does this have to be done differently like:

SELECT SUM(column1) AS column1, SUM(column2) AS column2, SUM(column3) AS column3 FROM tablename

Regards


Joe 8)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Not sure, what happened when you tried it? ;)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

what about:

Code: Select all

select column1+column2+column3 as total from .......
?
Post Reply