我正在尝试使用concat_ws
. 其中一个字段 ( is_logged
) 仅包含值0
或1
。yes
如果is_logged
字段的值是,我想连接1
,no
否则。
例如 -
concat_ws('', month,'-', year, ',Logged-', is_logged) info
电流输出 -Dec - 2020,Logged-1
预期输出 -Dec - 2020,Logged-Yes
如何做到这一点?谢谢!
在不同的 dbms 中可能会有所不同,但您可以这样做:
select concat_ws('',month,'-',year,',Logged-',case is_logged when 1 then 'yes' else 'no' end) info
from yourtable
我根据这个答案得到了这个工作-
concat_ws('', month,'-', year, ',Logged-',IFNULL(ELT(FIELD(is_logged,1),'Yes'),'No')) info