简体   繁体   English

MySQL和PHP排行榜查询

[英]MySQL & PHP leaderboard query

I have a set of players and I want to select the top 5 scores from the tables and print out the username and scores in descending order, what's the SQL statement for that? 我有一组玩家,我想从表格中选择前5个得分,并按降序打印出用户名和得分,这是什么SQL语句? and How to output the result? 以及如何输出结果?

SELECT * FROM yourtable ORDER BY score DESC LIMIT 5

Explanations: 说明:

SELECT * FROM yourtable : we select yourtable . SELECT * FROM yourtable :我们选择yourtable

ORDER BY score DESC : We order the results based on the column score and in descending order. ORDER BY score DESC :我们根据列score并以降序对结果进行排序。

LIMIT 5 : we limit the number of results by 5. LIMIT 5 :我们将结果数限制为5。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM