문제

Currently I'd have to write a query like this

SELECT * FROM table WHERE value1 > 5000 OR value2 > 5000 OR value3 > 5000 OR value4 > 5000

As you can see, the 5000 is compared to all of those columns. Ideally, you'd be able to write a query like this

SELECT * FROM table WHERE 5000 GREATER(value1,value2,value3,value4)

I know you can do

SELECT * FROM table WHERE 5000 IN(value1,value2,value3,value4)

But that tests for equality, not greater than.

Is there a way to do what I'm looking for?

도움이 되었습니까?

해결책

You could do:

SELECT *
FROM table
WHERE greatest(value1, value2, value3, value4, value5) > 5000 ;

As a note, this is not exactly the same. If any of the values are NULL this will return NULL, which is treated as false. The version with or will skip NULL values.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top