有什么办法可以找到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