【发布时间】:2014-03-14 02:13:56
【问题描述】:
任何人都知道如何从该表中获得最近的最高分:
----------------------------------------
|id |game_id |level |score |date |
----------------------------------------
|1 |0 |1 |90 |1391989720 |
|1 |0 |1 |95 |1391989721 |
|1 |0 |1 |95 |1391989722 |
|1 |1 |1 |4 |1391989723 |
|1 |1 |1 |8 |1391989724 |
|1 |1 |2 |6 |1391989725 |
----------------------------------------
到目前为止,我有这个:
SELECT progress_max.game_id,
progress_max.level,
progress_max.date AS max_date,
max_score
FROM
(
SELECT game_id, level, MAX(score) AS max_score
FROM cdu_user_progress
WHERE lesson_id = 1
GROUP BY game_id, level
) AS ms
JOIN cdu_user_progress progress_max ON progress_max.game_id = ms.game_id AND progress_max.level = ms.level AND progress_max.score = ms.max_score
WHERE progress_max.lesson_id = 1
GROUP BY game_id, level
但这只会让我获得 FIRST 最高分(日期 1391989721)...
【问题讨论】:
-
你想得到什么结果?最近的最大值 = ?
-
最近的最大值是日期 1391989722(分数 = 95)
-
你想要每个游戏和关卡吗?还是表格中只有一行结果?
-
是的,根据游戏和级别...
-
您的问题不清楚 id 代表什么以及应该如何处理。