So I have a table which has State1:
| id | column1 | column2 |
|---|---|---|
| 1 | myboolvalue | false |
| 1 | myecogvalue | 0 |
| 1 | myintvalue | 1700 |
State2
| id | column1 | column2 |
|---|---|---|
| 1 | myboolvalue | true |
| 1 | myecogvalue | 0 |
| 1 | myintvalue | 1700 |
In this case I want to have a where clause to satisfy following: select id where
- If the column1 == 'myboolvalue' then column2=true
- If the column1 == 'myecogvalue' then column2<=2
- If the column1 == 'myintvalue' then column2>1500
How can I write a SQL statement with this where clause? Please note these conditions need to be ANDed and not ORed All 3 conditions need to be satisfied - meaning in State1 nothing should be returned, but in State2 id 1 should be returned.
Note this is not RDBMS, this is an AWS athena query
This is what I have tried so far:
select * from (select DISTINCT(id) as id, tbl2.column1 as column1,tbl2.column2 as column2
FROM tbl1,tbl2
WHERE tbl1.id = tbl2.id)
WHERE
CASE column1
WHEN 'mybooleanvalue' THEN column2 = 'true'
WHEN 'myintvalue' THEN column2 > '1500'
WHEN 'myecogvalue' THEN column2 <= '2'
END
However, the CASE ORs all the conditions. I want to AND all.