gpt4 book ai didi

mysql - 从数据库表中的列中获取第三个最大值的 MySQL 查询可能是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:33 26 4
gpt4 key购买 nike

我被问过一次,

从 DB 表的列中获取第三个最大值的 MySQL 查询可能是什么?

请帮助我有多种方式来做到这一点。

谢谢

最佳答案

第一种方式:

第 n 最高列

   SELECT column FROM table ORDER BY column DESC LIMIT n-1, 1

第二种方式:(例如:对于第N高的薪水)未测试

SELECT id FROM EMPLOYEE E1 WHERE 
(N - 1) = (SELECT COUNT(distinct(SAL))
FROM EMPLOYEE E2
WHERE E2.SAL > E1.SAL )

基本逻辑:

You could sort the column into descending format and then just obtain the value from the nth row.

关于mysql - 从数据库表中的列中获取第三个最大值的 MySQL 查询可能是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6122696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com