[英]concat_ws a string based on the value of the column in the SQL query
我正在尝试使用concat_ws
连接来自多个字段的值。 其中一个字段 ( is_logged
) 仅包含值0
或1
。 如果is_logged
字段的值为1
,我想连接yes
,否则连接no
。
例如 - concat_ws('', month,'-', year, ',Logged-', is_logged) info
当前 output - Dec - 2020,Logged-1
预计 output - 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.