Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 选择第二、第三、第四、第五、最大数字_Php_Mysql_Sql_Select_Max - Fatal编程技术网

Php 选择第二、第三、第四、第五、最大数字

Php 选择第二、第三、第四、第五、最大数字,php,mysql,sql,select,max,Php,Mysql,Sql,Select,Max,我有一个关于如何选择表中第二、第三、第四和第五大数字的问题。要选择我使用的最大行,请执行以下操作: $max = SELECT max(money) FROM table 现在我想指定$second\u max、$third\u max、$fourth\u max和$fifth\u max 有人知道如何更改我以前的SQL select max轻松指定第二个max、第三个max等 我不想使用: select money from table order by money desc limit 5

我有一个关于如何选择表中第二、第三、第四和第五大数字的问题。要选择我使用的最大行,请执行以下操作:

$max = SELECT max(money) FROM table
现在我想指定$second\u max、$third\u max、$fourth\u max和$fifth\u max

有人知道如何更改我以前的SQL select max轻松指定第二个max、第三个max等

我不想使用:

select money from table order by money desc limit 5;

因为我希望它们都在不同的变量中。

从表中按货币顺序选择货币描述限制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;

这五行分别是max、secondary、,。。。金钱的价值。

在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;

哪个数据库管理系统、oracle或mss sql或MySQL从表中按货币描述限制0,1选择货币;从表ORDER BY money DESC LIMIT 1,1中选择第二个的money;从表ORDER BY money DESC LIMIT 2,1中选择第三个的money;等或者从表中选择“按货币说明顺序”限制0,5以获得降序排列的前5名从“表”中选择“货币”按“货币说明顺序”限制1,4将返回第2、3、4和5行。显然,如果您想获得所有5行,您需要按照其他人的建议执行,并使用limit 5。