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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
"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. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|