我想获得每个用户的最高分,但分数将填入用户ID(INT)或昵称(VARCHAR)列;另一个将为空。
理想情况下会得到这样的结果:
nickname, userid, score
abc, NULL, 1500
NULL, 22, 1250
NULL, 15, 1100
xyz, NULL, 750
答案 0 :(得分:1)
SELECT nickname, userid, MAX(score)
FROM my_table
GROUP BY nickname, userid
答案 1 :(得分:0)
Select COALESCE(nickname, userid) as userid_or_name, max(score) from yourtable
Group by COALESCE(nickname, userid)
答案 2 :(得分:0)
SELECT user_id,user_name,MAX(score) FROM user_score
GROUP BY user_id,user_name