select
e_id
,CASE WHEN w_id in ('1','2') THEN w_id ELSE 0 END as new_w_id
,CASE WHEN w_id = 1 THEN fee END as value1
,CASE WHEN w_id = 2 THEN fee END as value2
,CASE WHEN w_id not in ('1','2') THEN fee END as value3
from table1
The above code gives me a result like:
e_id | new_w_id | value1 | value2 | value3
1 | 1 | 100 | null | null
1 | 2 | null | 150 | null
1 | 0 | null | null | 50
1 | 0 | null | null | 150
but I'd like to group by e_id and get result like:
e_id | new_w_id | value1 | value2 | value3
1 | 1 | 100 | null | null
1 | 2 | null | 150 | null
1 | 0 | null | null | 200
I've tried
group by e_id
and
group by e_id, CASE WHEN w_id in ('1','2') THEN w_id ELSE 0 END
but neither of these are grouping my data as I'd like. Is there a solution to this?
CREATE TABLE
statement and some of your test data.group by e_id, CASE WHEN w_id in ('1','2') THEN w_id ELSE 0 END
?