7

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
4

2 に答える 2

20

GREATESTを使用する必要があります

そのように

    select id from tablex where GREATEST(column1, column2, column3) > 69
于 2013-07-24T22:03:38.090 に答える