I have a table in which there is a varchar column 'someid'
and some timestamp columns:
'date_1', ... , date_4
and 'xdate_1', ... , xdate_4
I am trying to select two of them depending on 'someid' value, but had no luck until now. I am sure that this is syntax, googling also didn't help as all the examples were similar to my query.
Heres what I'm trying to do:
select
case
when someid = 1 then date_1
when someid = 2 then date_2
when someid = 3 then date_3
when someid = 4 then date_4
,case
when someid = 1 then xdate_1
when someid = 2 then xdate_2
when someid = 3 then xdate_3
when someid = 4 then xdate_4
from mytable;
You forgot the end
select
case
when someid = 1 then date_1
when someid = 2 then date_2
when someid = 3 then date_3
when someid = 4 then date_4
end as col1
,case
when someid = 1 then xdate_1
when someid = 2 then xdate_2
when someid = 3 then xdate_3
when someid = 4 then xdate_4
end as col2
from mytable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With