[英]concat_ws a string based on the value of the column in the SQL query
I am trying to concatenate values from multiple fields using concat_ws
.我正在尝试使用concat_ws
连接来自多个字段的值。 One of the fields ( is_logged
) contains only the values 0
or 1
.其中一个字段 ( is_logged
) 仅包含值0
或1
。 I want to concatenate yes
if the value of is_logged
field is 1
and no
otherwise.如果is_logged
字段的值为1
,我想连接yes
,否则连接no
。
Eg - concat_ws('', month,'-', year, ',Logged-', is_logged) info
例如 - concat_ws('', month,'-', year, ',Logged-', is_logged) info
Current output - Dec - 2020,Logged-1
当前 output - Dec - 2020,Logged-1
Expected output - Dec - 2020,Logged-Yes
预计 output - Dec - 2020,Logged-Yes
How can this be achieved?如何做到这一点? Thanks!谢谢!
can be different in different dbms but you can do this:在不同的 dbms 中可能会有所不同,但您可以这样做:
select concat_ws('',month,'-',year,',Logged-',case is_logged when 1 then 'yes' else 'no' end) info
from yourtable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.