gpt4 book ai didi

mysql - 列的差异。返回变量顶部重复结果

转载 作者:行者123 更新时间:2023-11-30 23:37:35 24 4
gpt4 key购买 nike

我有一个查询返回两列中最大的差异。让我们说它是这样的:

| result |
5
5
5
4
4
3
2

我怎样才能让它每次都返回所有排名靠前的结果? (5, 5, 5)

我不是在寻找 LIMIT 3,因为结果各不相同,有时只有一个最高数字,等等。

我现在的查询是这样的:

SELECT MAX(column1 - column2) as result
FROM table
WHERE othercolumn = somecondition
GROUP by id
ORDER BY results asc

最佳答案

SELECT MAX(column1 - column2) as result
FROM table
WHERE othercolumn = somecondition
GROUP by id
HAVING result =
(select max(column1 - column2) FROM table WHERE othercolumn = somecondition)
ORDER BY id;

关于mysql - 列的差异。返回变量顶部重复结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6243175/

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