gpt4 book ai didi

mysql - 在 1 个 if 子句下有多个列

转载 作者:行者123 更新时间:2023-11-29 05:20:49 25 4
gpt4 key购买 nike

我正在尝试编写如下查询

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;

它给出了语法错误。有什么方法可以让我写出相同的内容吗?

最佳答案

试试这个:

我想你的 drophip 是 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;

关于mysql - 在 1 个 if 子句下有多个列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26095172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com