简体   繁体   English

将多个列与Teradata合并在一起

[英]Combine several columns in one with Teradata

I have 10 columns and their values could be either null, or a name of a fruit. 我有10列,它们的值可以是null,也可以是水果的名称。

I would like to add another column with all the fruits that every row has. 我想添加另一列,其中包含每行所有的水果。 I have used Concat(column1 , column2,..., column10) as name. 我使用Concat(column1,column2,...,column10)作为名称。

Issue : There are no commas coming on the result and if I add the comma before concatenating, we are having them together, the last word is also a comma. 问题:结果中没有逗号,如果我在连接之前添加逗号,我们将它们放在一起,最后一个单词也是逗号。

Any ideas? 有任何想法吗?

Thanks! 谢谢!

You can use the standard concatenation (||) in conjunciton with COALESCE function, which returns the value of the first non-null argument. 您可以在COALESCE函数的结合中使用标准串联(||),该函数返回第一个非null参数的值。

Example: 例:

select coalesce(column1||',', '')||coalesce(column2||',', '')|| ... ||coalesce(column10||, ''); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM