[英]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
因為我想在一列中輸出
我最近遇到了相同的問題,我使用了||。 (雙管道)以連接到列。
我還必須在查詢中編寫一個包裝器以解決該問題。
下面是我的查詢最后的摘要。
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.