我在表1中有以下记录
c1 c2 c3
----------
A B C
Run Code Online (Sandbox Code Playgroud)
如何合并c1 c2和c3以便输出
在输出之间使用空格的ABC我使用了concat函数,但它没有采用3个参数
select concat (c1,c2,c3) from table1
Run Code Online (Sandbox Code Playgroud)
我不能select * from table1在一列中运行,因为我想要输出
Gil*_*lit 13
这至少适用于z/OS版本:
select c1 concat ' ' concat c2 concat ' ' concat c3
Run Code Online (Sandbox Code Playgroud)
了解DB2 文档
小智 7
我最近遇到了相同的问题,我使用了||。(双管道)以连接到列。
我还必须在查询中编写一个包装器以解决该问题。
下面是我的查询最后的摘要。
select a1 || a2 as a2, a3 || a4 as a4 --wrapper 2
from (
select '"service":"' as a1,a2, '","total":' as a3, a4 --wrapper 1
from (
select distinct(a2),count(*) as a4
from abc.table
group by a2
order by a2)
);
Run Code Online (Sandbox Code Playgroud)
以下是来自查询的输出:
"service":"ABC" , "total":123
Run Code Online (Sandbox Code Playgroud)