【问题标题】:how to get 5th maximum value from a table in sql?如何从sql中的表中获取第5个最大值?
【发布时间】:2014-05-28 07:54:11
【问题描述】:

我有一个名为Products 的表,其中有一列Prices。 如何从该表中获得第 5 个最大值?

我找到了两种方法:

=1=

select max(id) 
from EMP A 
where 5=( select count(distinct(id)) 
          From EMP  B 
          where B.ID>=A.ID )

=2=

SELECT * 
FROM Products Price1 
WHERE (4) = (SELECT COUNT(DISTINCT(Price2.Price))
             FROM products Price2 
             WHERE Price2.Price > Price1.Price)

【问题讨论】:

标签: sql


【解决方案1】:

为什么要使用这么复杂的查询:

使用这个简单的->

SELECT * FROM products ORDER BY price LIMIT 5, 1

【讨论】:

    【解决方案2】:

    类似这样的:

    SELECT * 
    FROM products
    ORDER BY price DESC
    LIMIT 5, 1
    

    【讨论】:

      猜你喜欢
      • 2017-02-08
      • 1970-01-01
      • 2021-05-06
      • 2019-03-09
      • 1970-01-01
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多