从 MySQL table 获得顶级球员

Get top players from the MySQL table

我在 MySQL 数据库中有 table,其中包含两个字段 user_idscore。这个 table 是一种日志 table 所以一个 user_id 可以有多个行具有不同的分数。我怎样才能从这个 table 中获得得分最高的前 10 名用户?

SELECT DISTINCT user_id
FROM your_table
ORDER BY score DESC
LIMIT 10

编辑:

SELECT DISTINCT *
FROM your_table
WHERE (user_id, score) IN (SELECT user_id, MAX(score) AS score
                           FROM your_table
                           GROUP BY user_id)
ORDER BY score DESC
LIMIT 10

SqlFiddleDemo

这是基本的,你应该更加努力;这是您可以使用的模板 -

SELECT TOP 10 distinct * 
FROM people 
WHERE names='SMITH'
ORDER BY names asc