gpt4 book ai didi

来自 3 个不同列的 Mysql 最大值

转载 作者:可可西里 更新时间:2023-11-01 06:34:41 25 4
gpt4 key购买 nike

有没有办法找到 3 个不同列的最大值?我正在尝试查找任何 3 列值高于指定值的记录,并试图避免在查询中进行类似这样的操作:

column1 > 69 or column2 > 69 or column3 > 69

表结构是这样的:

id | column1 | column2 | column3
1 | 5 | 4 | 3
2 | 70 | 1 | 65
3 | 66 | 3 | 90

然后像这样选择:

select id from tablex where column1 > 69 or column2 > 69 or column3 > 69

-- but with better query, a bit prettier like this (it doesn't work of course)

select id from tablex where MAX(column1, column2, column3) > 69

最佳答案

你需要使用GREATEST

那样

    select id from tablex where GREATEST(column1, column2, column3) > 69

关于来自 3 个不同列的 Mysql 最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17845555/

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