mysql SUM function

This is a discussion on mysql SUM function within the MySQL Database forums, part of the Database Forums category; Hello everyone. I have a (faily simple) question regarding mysql SUM function Here's my situation: I got 2 tables ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-06-2006
redpixel
 
Posts: n/a
Default mysql SUM function

Hello everyone.

I have a (faily simple) question regarding mysql SUM function

Here's my situation:
I got 2 tables in mysql database. First one contains users and their
informations and second one contains steps (yes, steps.users are able
to enter amount of walked steps each day and each row equals one day).
Obviously steps in Steps table are identified with ID (UserID) to
establish connection to users table.

And my question is:

How do I select select all users from tblwalkers table and SUM of all
steps for each user (that is selected from tblSteps table)?
I'm trying to output this list on a page using php:

mysql_query("SELECT tblwalkers.ID, SUM(tblsteps.Steps) AS steps FROM
tblwalkers, tblsteps WHERE tblwalkers.ID = tblsteps.userID");
$sql_result = mysql_fetch_array($sql);

do {

$total_steps = $sql_result['steps'];
$user_id = $sql_result['ID'];

echo "member:".$user_id;
echo "total steps:".$total_steps;
echo "<br />";

} while ($sql_result = mysql_fetch_array($sql));



--
SELECT tblwalkers.ID, SUM(tblsteps.Steps) AS steps FROM tblwalkers,
tblsteps WHERE tblwalkers.ID = tblsteps.userID
is not working

nor is

SELECT tblwalkers.ID, tblsteps.UserID, SUM(tblsteps.Steps) AS steps
FROM tblwalkers Inner Join tblsteps ON tblwalkers.ID = tblsteps.userID


Can anybody hook me up with a solution to this problem?
Any help is appreciated.

Reply With Quote
  #2 (permalink)  
Old 09-06-2006
redpixel
 
Posts: n/a
Default Re: mysql SUM function

Oh, heh, I just figured it out.

Thanx anyway

Reply With Quote
  #3 (permalink)  
Old 09-12-2006
Bosconian
 
Posts: n/a
Default Re: mysql SUM function

"redpixel" <peter.tikhomirov@gmail.com> wrote in message
news:1157506857.373818.98030@m73g2000cwd.googlegro ups.com...
> Oh, heh, I just figured it out.
>
> Thanx anyway
>


It's always nice to share the solution when answering your own question so
that others might learn.


Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



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


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0