簡體   English   中英

DB2:合並三列輸出的函數

[英]DB2: Function to merge 3 column output

我在表1中有以下記錄

c1  c2  c3
----------
A   B   C

如何合並c1 c2和c3以便輸出想要

ABC在輸出之間有空格,我使用了concat函數,但它沒有接受3個參數,例如

select concat (c1,c2,c3) from table1

我無法在select * from table1運行select * from table1因為我想在一列中輸出

至少在z / OS版本中有效:

select c1 concat ' ' concat c2 concat ' ' concat c3

了解DB2 文檔

我最近遇到了相同的問題,我使用了||。 (雙管道)以連接到列。

我還必須在查詢中編寫一個包裝器以解決該問題。

下面是我的查詢最后的摘要。

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)
);

以下是來自查詢的輸出:

"service":"ABC" , "total":123

嘗試這個。

select concat(concat (c1,c2),c3) from table1

從SQL轉換為DB2時遇到問題。 該頁面有所幫助,但最終我做了一些更改:

SELECT
RTRIM(C1) || '' || C2 as CFULL
FROM TABLE

SELECT C1 CONCAT '' CONCAT ( C2 CONCAT '' CONCAT C3) FROM TABLENAME

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM