Jump to content

MySQL Report


wildasIwanabe

Recommended Posts

Hi,

 

I've been playing around with some data in MySQL.  I can manage to enter the data with no problem but I'm a having a little problem trying to generate a report from the data.

 

Basically, the data contains 3 fields.  Date, distance ran and Time taken.  Whenever I go for a run, I enter my results into the mysql table.  I then have a script to get the best time for each distance ran.  That part works great, but the date that the best time was ran is wrong.  Please see my attachment for a better understanding.  I have several 5km runs, and my best time was in June, but it shows that it was in April.

 

This is the query I wrote in PHP...

$query = "SELECT MIN(time), distance, rundate FROM running group by distance";

 

Am I missing something from the query ???

 

thanks.

 

 

 

 

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/162399-mysql-report/
Share on other sites

Something like this may get the results that you want:

select allRuns.* from(
select time, distence, date from location 
)allRuns join(
select min(time) as time, distence 
from running 
group by distance
) minDistence 
on      allRuns.time = minDistence.time 
	and allRuns.distence = minDistence.distence

Although I'm sure there is a better way, I just can't think of it right now.

Link to comment
https://forums.phpfreaks.com/topic/162399-mysql-report/#findComment-857515
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.