【问题标题】:concat_ws a string based on the value of the column in the SQL queryconcat_ws 基于 SQL 查询中列的值的字符串
【发布时间】:2021-04-06 17:53:18
【问题描述】:

我正在尝试使用concat_ws 连接来自多个字段的值。其中一个字段 (is_logged) 仅包含值 01。如果is_logged 字段的值为1no 否则我想连接yes

例如- concat_ws('', month,'-', year, ',Logged-', is_logged) info

电流输出 - Dec - 2020,Logged-1

预期输出 - Dec - 2020,Logged-Yes

如何做到这一点? 谢谢!

【问题讨论】:

  • 你用的是sql server吗?

标签: sql concat-ws


【解决方案1】:

在不同的 dbms 中可能会有所不同,但您可以这样做:

select concat_ws('',month,'-',year,',Logged-',case is_logged when 1 then 'yes' else 'no' end) info
from yourtable

【讨论】:

    【解决方案2】:

    我根据 answer 得到了这个工作 -

    concat_ws('', month,'-', year, ',Logged-',IFNULL(ELT(FIELD(is_logged,1),'Yes'),'No')) info
    

    【讨论】:

      猜你喜欢
      • 2019-04-16
      • 2016-05-18
      • 2019-09-11
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 2016-05-15
      • 2023-02-23
      • 1970-01-01
      相关资源
      最近更新 更多