I have a table completion_log
that has team_id
, level
and completion_time
. When each team completes a level, there will be a record inserted with the corresponding level and time values. What is the best SQL query to create a leaderboard from the data - List the teams in descending order of their highest level
value and if the highest levels are same, sort by the completion_time
in ascending order?
I tried something like:
SELECT team_id, max(level) FROM completion_log GROUP BY team_id ORDER BY max(level)
While this almost does the job, this doesn't sort by completion_time
when the values for max(level)
for each team are the same. How to do it?