0

I have a quiz report table which shows a report for every quiz a user takes. I need to create a leaderboard from this, which shows the top users best score, filtering by points and then time taken.

here is a link to a sql fiddle http://sqlfiddle.com/#!2/65fbf0/1

I am really struggling as i need to filter the results by two columns for one user, my ideal result would be

Results for Quiz id 1
---------------------------------------------------------------   
| user_id  |  points  |  time_spend  |  start_dt  |  quiz_id  |
| 1        |  3       | 0.5          | May,15 2015|  1        |
| 2        |  3       | 0.8          | May,15 2015|  1        |
| 3        |  2       | 0.5          | May,15 2015|  1        |

Then a separate query for all quiz's showing the results from the last week.

Results from all Quizzs
---------------------------------------------------------------   
| user_id  |  points  |  time_spend  |  start_dt  |  quiz_id  |
| 1        |  3       | 0.5          | May,15 2015|  1        |
| 2        |  3       | 0.8          | May,13 2015|  3        |
| 3        |  2       | 0.5          | May,12 2015|  2        |
2
  • What do you mean by filtering? Ordering maybe? And please produce a minimal example without all the irrelevant columns, then include the table definition, sample data and your best try at the query here. Commented May 27, 2015 at 4:46
  • I have a simply mysql query in for now, but i need to limit this to a user_id best entry: SELECT user_id, quiz_id, points, time_spend, start_dt FROM ProQzQuizReport WHERE quiz_id = 1 ORDER by points DESC, time_spend ASC I have updated the sql fiddle sqlfiddle.com/#!2/65fbf0/7
    – Gismmo
    Commented May 27, 2015 at 8:24

1 Answer 1

0

Solution to the query:

select *
from (
  select *
  from ProQzQuizReport
  order by points desc, time_spend asc) a
group by user_id;

http://sqlfiddle.com/#!2/65fbf0/9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.