Ingis
Ingis

Reputation: 25

How to make two ''where' conditions on SQL select query

I have a table like this

column 1| column2 | column 3|

01               45               heavy
02               50                easy
04              100               middle

I want a result that will show all records that if in 'column 3' is 'heavy' then 'column 2' must have value greater then 50, and if in 'column 3' is not 'heavy' then 'column 2' must have value greater then 90

Upvotes: 0

Views: 57

Answers (2)

melpomene
melpomene

Reputation: 85767

You can use case / when:

select ...
where column2 > (
    case column3
        when 'heavy' then 50
        else 90
    end
)

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269803

You can translate your logic directly into a where clause:

where (column3 = 'heavy' and column2 > 50) or
      (column3 <> 'heavy' and column2 > 90)

Upvotes: 4

Related Questions