Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2007, 05:00 AM   PM User | #1
utinaeniduin
New Coder

 
Join Date: Mar 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
utinaeniduin is an unknown quantity at this point
adding values of a single column

how can i add all the values of one column of the table to get a total?
utinaeniduin is offline   Reply With Quote
Old 01-17-2007, 09:32 AM   PM User | #2
koyama
Senior Coder

 
koyama's Avatar
 
Join Date: Dec 2006
Location: Copenhagen, Denmark
Posts: 1,246
Thanks: 1
Thanked 5 Times in 5 Posts
koyama will become famous soon enough
Code:
SELECT SUM(myColumn) FROM myTable WHERE 1
koyama is offline   Reply With Quote
Old 01-17-2007, 12:54 PM   PM User | #3
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
Note that the WHERE 1 is not necessary.
guelphdad is offline   Reply With Quote
Old 01-17-2007, 04:44 PM   PM User | #4
utinaeniduin
New Coder

 
Join Date: Mar 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
utinaeniduin is an unknown quantity at this point
cool. now how do i store that sum in a variable?
utinaeniduin is offline   Reply With Quote
Old 01-17-2007, 05:02 PM   PM User | #5
koyama
Senior Coder

 
koyama's Avatar
 
Join Date: Dec 2006
Location: Copenhagen, Denmark
Posts: 1,246
Thanks: 1
Thanked 5 Times in 5 Posts
koyama will become famous soon enough
I guess you are using php?
PHP Code:
$sql "SELECT SUM(myColumn) FROM myTable";
$result mysql_query($sql);
list(
$sum) = mysql_fetch_row($result);   // now $sum = 'the sum' 
koyama is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:40 AM.


Advertisement
Log in to turn off these ads.