首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sql中带有回车符的多个coalesce和ifnull字符串(db2)

问sql中带有回车符的多个coalesce和ifnull字符串(db2)
EN

Stack Overflow用户
提问于 2017-10-13 00:10:40
回答 1查看 125关注 0票数 0

我正在尝试使用coalesce和ifnull将多个数据点合并到一个单元格中,并在组合的数据点之间使用回车。如果我删除第二个coalesce语句,它就可以工作,但到目前为止,没有机会组合两组以上的数据。任何想法都将不胜感激。我在DB2中使用SQL。

基本上,我希望从SQL语句中获得以下结果:

Bob,LCE

弗雷德,LBD

朱莉,LNJ

代码语言:javascript
复制
select 
nullif(b.column03,'') || ', ' || nullif(b.column04,'')
|| coalesce(chr(10) || nullif(b.column05,'') || ', ' || 
nullif(b.column06,''),'')
|| coalesce(chr(10) || nullif(b.column07,'') || ', ' || 
nullif(b.column08,''),'')
as "Presenter/Agency"
from  [ETL redacted] b
order by 1,2,3,4
EN

回答 1

Stack Overflow用户

发布于 2017-10-13 23:57:31

代码语言:javascript
复制
case when coalesce(column3,column04) > '' then
   column03  || ', ' || b.column04 
else '' end ||
case when coalesce(column05,column06) > '' then 
   case when coalesce(column03,column04) > '' then chr(10) else '' end ||
   column05  || ', ' || b.column06 
else '' end ||
case when coalesce(column07,column08) > '' then 
   case when coalesce(column03,column04,column05,column06) > '' then chr(10) else '' end ||
   column07  || ', ' || b.column08 
else '' end 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46714299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档