mysql group by distinct

有这样一张表,记录着用户和得分


1、需要展示一个排行榜

SELECT user_id, MAX(score) AS max_score FROM score_record GROUP BY user_id


2、排行榜中只展示60分以上的

SELECT user_id, max(score) as max_score from score_record GROUP BY user_id having max_score > 60 ORDER BY max_score desc


3、如果只是单纯的去重,查看有多少用户有得分记录

SELECT COUNT(DISTINCT(user_id)) as user_count from score_record


3、如果只是单纯的去重,查看都是哪些用户?

SELECT DISTINCT(user_id) AS user_count FROM score_record


你可能感兴趣的:(mysql group by distinct)