Jump to content

Recommended Posts

Hey Everyone,

 

I am trying to display some data i have in my mysql database in a table.  im having a problem with the SQL to do it though.  what i am trying to do is display the amount of calories for a day, there could be multiple entries for a day.

 

This is the data from my database:

+-----------------------------+-----------------+
| substring(r.ride_date,1,10) | calories_burned |
+-----------------------------+-----------------+
| 2010-01-08                  |             250 | 
| 2010-01-08                  |             123 | 
| 2010-01-08                  |             123 | 
| 2010-01-10                  |             456 | 
+-----------------------------+-----------------+

What i want is to select the the distinct days (2010-01-08 and 2010-01-10) and add up the calories for them.

 

the SQL i am using is this:

select distinct(substring(r.ride_date,1,10)), sum(calories_burned)
from rides r 
join usersrides ur on r.ride_date = ur.ride_date 
join users u on ur.userid = u.userid 
where u.userid='1';

this does not produce the result im looking for though, it just sums up all the calories burned into one row

+-------------------------------+----------------------+
| (substring(r.ride_date,1,10)) | sum(calories_burned) |
+-------------------------------+----------------------+
| 2010-01-08                    |                  952 | 
+-------------------------------+----------------------+

 

Please can someone point me in the rite direction

Thanks in Advance,

-Beano

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/188040-sql-problem-selecting-distinct-data/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.