我正在尝试编写如下的查询
select
if drophip = 1 then
0 as a,
0 as b,
1 as c,
1 as d
else if drophip = 0 then
1 as a,
1 as b,
0 as c,
0 as d
end if;
from tabl1;
它给出了语法错误。我有什么方法可以写同样的东西吗?
答案 0 :(得分:3)
试试这个:
我认为您的弃权是boolean
字段。
select
case
when drophip = 1 then 0
else 1
end as a,
case
when drophip = 1 then 0
else 1
end as b,
case
when drophip = 1 then 1
else 0
end as c,
case
when drophip = 1 then 1
else 0
end as d
from tabl1;