来自3个不同列的MySQL最大值 [英] Mysql max value from 3 different columns
本文介绍了来自3个不同列的MySQL最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法可以找到3个不同列的最大值?我正在尝试查找3列值均高于指定值的记录,并尝试避免在查询中进行如下操作:
Is there any way to find maximum value of 3 different columns? I'm trying to find records with any of 3 columns value higher than specified value and trying to avoid making something like this in query:
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
推荐答案
,您需要使用喜欢
select id from tablex where GREATEST(column1, column2, column3) > 69
这篇关于来自3个不同列的MySQL最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文