我有桌面球员的结果:
id | id_user | timems | status | cancel
玩家在开始游戏时选择两种状态:1或2。我列出最佳时间排名:
SELECT *, MIN(timems) AS besttime
FROM `wyniki`
WHERE NOT cancel=1
GROUP BY id_user
ORDER BY MIN(timems) ASC
这是有效的,但我不知道'状态'的最佳时间是什么。
此查询容易出错
你可以这样做
SQL查询:
SELECT id_user, status , MIN(timems) AS besttime FROM `wyniki`
WHERE NOT cancel=1 GROUP BY id_user, status ORDER BY MIN(timems) ASC
SELECT id_user,
MIN(case when status = 1 then timems else null end) AS best_time_1,
MIN(case when status = 2 then timems else null end) AS best_time_2
FROM wyniki
WHERE cancel <> 1
GROUP BY id_user
ORDER BY MIN(timems) ASC