如何在mytable中选择前5个最大值 [英] how to select top 5 max values in mytable

查看:90
本文介绍了如何在mytable中选择前5个最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我进行Mysql查询. 我的表包含很多行.现在我要从该表中检索5行.

Please help me with Query in Mysql.. i am Having table contains lot of rows .now i want retrive the 5 rows from that table.

我的要求是我要从该表中选择表中列名即金额"的前5个最高值.N个记录中,我需要该表中前5个最高的记录

my requirement is top maximum 5 values in that table "column name is amount" i want select from that table.outof N records i need top max 5 records from table

谢谢你

推荐答案

只需按(降序)数量对行进行排序,并排在前5位:

Just order the rows by (descending) amount and take the top 5:

SELECT amount FROM mytable ORDER BY amount DESC LIMIT 5

请注意,除非您在amount列上有索引,否则这将导致全表扫描.如果表中的行数很大(即成千上万),则可能会影响性能.

Note that this will result in a full table scan unless you have an index on the amount column. This could affect performance if the number of rows in the table is very large (i.e. many thousands).

这篇关于如何在mytable中选择前5个最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆