0

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

基本上我想从 SQL 语句中得到以下结果:

鲍勃,LCE

弗雷德,LBD

朱莉,LNJ

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
4

1 回答 1

0
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 
于 2017-10-13T15:57:31.250 回答