Anyone know how I can get the date that corresponds to the maximum score per game_id, per level please:
----------------------------------------
|id |game_id |level |score |date |
----------------------------------------
|1 |0 |1 |90 |1391989720 |
|1 |0 |1 |95 |1391989721 |
|1 |1 |1 |4 |1391989722 |
|1 |1 |1 |8 |1391989723 |
|1 |1 |2 |6 |1391989724 |
----------------------------------------
SELECT cdu_user_progress.game_id,
cdu_user_progress.level,
max_score,
cdu_user_progress.date
FROM
(
SELECT game_id, level, MAX(score) AS max_score
FROM cdu_user_progress
GROUP BY game_id, level
) AS ms
JOIN cdu_user_progress ON cdu_user_progress.game_id = ms.game_id AND
cdu_user_progress.level = ms.level AND
cdu_user_progress.score = ms.max_score
Now what if I ALSO want to get the score for the FIRST game_id (per level) and it's date, to get this output:
-----------------------------------------------------------------
|game_id |level |max_score |max_date |first_score |first_date |
-----------------------------------------------------------------
|0 |1 |95 |1391989721 |90 |1391989720 |
|1 |1 |8 |1391989723 |4 |1391989722 |
|1 |2 |6 |1391989724 |6 |1391989724 |
-----------------------------------------------------------------