[英]Get value from MySQL table, show only top ten highest and top ten lowest
I have a table like this: 我有一张这样的桌子:
Username Rating
1 xxxxxxxx -1
2 xxxxxxxx 2
3 xxxxxxxx 5
4 xxxxxxxx -2
5 xxxxxxxx 4
(Imagine if the table was bigger and had more than 20 rows). (想象一下如果表更大并且有20多个行)。 I want to write a MySQL statement in PHP that will return two lists: a list of the top ten highest values ordered by largest first, and a list of the top ten lowest values, ordered lowest first. 我想在PHP中编写一个MySQL语句,该语句将返回两个列表:最大的前十个最高值的列表(按最大的顺序排列),以及前十个最低值的列表(按顺序的最低顺序排列)。 How would I go about this? 我将如何处理?
Ten highest: 十大最高:
SELECT Username, Rating FROM <Table> ORDER BY Rating DESC LIMIT 10;
Ten lowest: 最低的十:
SELECT Username, Rating FROM <Table> ORDER BY Rating ASC LIMIT 10;
You order the result and use limit 10
您订购结果并使用limit 10
select *
from mytable
order by rating
limit 10
or the top highest values 或最高的值
select *
from mytable
order by rating desc
limit 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.