![](/img/trans.png)
[英]how to skip iteration of while loop in associative array means we want to execute first ,second, fourth,fifth like this?
[英]Select second, third, fourth, fifth, largest number
我有一个关于如何在表中选择第二,第三,第四和第五大数字的问题。 要选择我使用的最大行:
$max = SELECT max(money) FROM table
现在,我要指定$second_max
$third_max
, $fourth_max
, $fourth_max
和$fifth_max
。
有人知道如何更改我以前的SQL select max()
轻松指定第二个max,第三个max等吗?
我不想使用:
select money from table order by money desc limit 5;
因为我希望它们全部位于不同的变量中。
select money from table order by money desc LIMIT 5
可能最简单的方法是将它们放在单独的行上:
select t.money
from table t
group by t.money
order by money desc
limit 5;
The next easiest thing is to put them in a comma-separated list:
select group_concat(money order by money desc) as monies
from (select t.money
from table t
group by t.money
order by money desc
limit 5
) T
只是这个:
SELECT money
FROM yourtable
ORDER BY money DESC
LIMIT 5
假设您实际上在表中有5条以上的记录,那么您将获得5条记录的结果集,并按最高货币值排序。
使用SQL
select money from table order by money desc limit 5;
五行分别是最大,次级,...货币价值。
在ORACLE中,您可以执行以下操作:
SELECT *
FROM (
SELECT ADRESSID,
ROW_NUMBER() OVER (ORDER BY ADRESSID DESC) AS ROW_NUM
FROM ADRESSTABLE
) t
WHERE ROW_NUM = 1
OR ROW_NUM = 3
OR ROW_NUM = 5;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.