DETAILS
I want to find the difference between start and stop times(duration) for each test taken then rank users according to the highest score and lowest duration for each test. Ultimately I will use PDO to do this in mysql. So far though I’ve just been working on the sql. I think I’m pretty close now, but am unsure how to combine the information into one query.
WHAT I’VE GOT(untested).
I have the following table called testresults
--------------------------------------------------------------------
| index | id | start | stop | score|
--------------------------------------------------------------------
| 1 | 23 | 2012-06-06 07:30:20 | 2012-06-06 07:30:34 | 100 |
--------------------------------------------------------------------
In my select statement I want to get the id and the score along with the calculated duration.
I can get duration for any test taken today with the below query.
SELECT TIMESTAMPDIFF(SECOND,stop,start) AS duration
FROM testresults WHERE `start` >= DATE(NOW())
Then I sort the results based on rank. Rank is determined according to score and duration. Top place goes to the highest score with the shortest duration.I believe I can do that with something like this:
ORDER BY score DESC, duration ASC
I only want maybe 100 entries so,
LIMIT 100
QUESTION
How can I combine the above information into 1 query?
This will work pretty good. You’ll also need to put
id&scoreinSELECTstatement.