开发者

Select n largest values from a table

开发者 https://www.devze.com 2023-01-09 15:01 出处:网络
How can I select the 100 largest rows in a table based on a column \'score\'? I can find the largest score in the \'score\' colum开发者_高级运维n with:

How can I select the 100 largest rows in a table based on a column 'score'?

I can find the largest score in the 'score' colum开发者_高级运维n with:

SELECT max(score) FROM mTable

And then obtain that row(s):

SELECT * FROM mTable WHERE score=largestScore

But how would I wrap this up and obtain the following 99 lower scored rows?

Thanks.


Use:

SELECT t.*
FROM MTABLE t
ORDER BY t.score DESC
LIMIT 100


Formatted:

Select * 
 from mtable 
order by score desc  
limit 100


SELECT columnList
FROM mTable
ORDER BY score DESC
LIMIT 100
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号