wildasIwanabe Posted June 16, 2009 Share Posted June 16, 2009 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 More sharing options...
Gamic Posted June 16, 2009 Share Posted June 16, 2009 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 More sharing options...
wildasIwanabe Posted June 17, 2009 Author Share Posted June 17, 2009 Thanks Gamic. That works. Wow, I didn't realize it had to be that complicated. If you don't mind, can you please explain the syntax to me. I don't understand that minDistance part. Sorry, I'm still new at this. Link to comment https://forums.phpfreaks.com/topic/162399-mysql-report/#findComment-857903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.