0
我試圖在project_id匹配時跨行將多個名稱組合到一列。我從一個自我加入開始,但無法按照我想要的方式工作,我非常確定有一個函數或cte可以更輕鬆地完成此任務。詢問方向。使用db2。將多行組合到一個
這是我迄今爲止沒有工作,併產生-104錯誤。
(
SELECT
DP.D_P_ID, DP.project_name,
DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST AS
FROM Fact_table as FAT
INNER JOIN D_P DP ON FAT.D_P_ID = DP.D_P_ID
INNER JOIN B_U_P BUP on DP.D_P = BUP.D_P_ID
INNER JOIN D_U DU2 ON BUP.D_U_ID = DU2.D_U_ID
INNER JOIN D_Date DD ON FAT.START_DATE_ID = DD.DATE_KEY
INNER JOIN D_A DA ON FAT.D_A_ID = DA.D_A_ID
WHERE (( (DD.DATE_VALUE >= '2013-01-01')
OR (DD.DATE_VALUE < '2014-01-01')
OR (DD.DATE_VALUE <= '2013-01-01')))
AND DA.M_NAME = 'Mandy'
AND BUP.USER_FLAG = 'Y'
GROUP BY DP.D_P_ID, DP.project_name, DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST
ORDER BY DP.project_name
) PI1
join
(
SELECT
DP.D_P_ID, DP.project_name,
DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST AS
FROM Fact_table as FAT
INNER JOIN D_P DP ON FAT.D_P_ID = DP.D_P_ID
INNER JOIN B_U_P BUP on DP.D_P = BUP.D_P_ID
INNER JOIN D_U DU2 ON BUP.D_U_ID = DU2.D_U_ID
INNER JOIN D_Date DD ON FAT.START_DATE_ID = DD.DATE_KEY
INNER JOIN D_A DA ON FAT.D_A_ID = DA.D_A_ID
WHERE (( (DD.DATE_VALUE >= '2013-01-01')
OR (DD.DATE_VALUE < '2014-01-01')
OR (DD.DATE_VALUE <= '2013-01-01')))
AND DA.M_NAME = 'Mandy'
AND BUP.USER_FLAG = 'Y'
GROUP BY DP.D_P_ID, DP.project_name, DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST
ORDER BY DP.project_name
) PI2 on PI1.d_p_id = PI2.d_p_id
數據例如:
這是我需要的結果是:
什麼是您的DB2版本和平臺? – mustaccio
我正在使用版本號爲9070500的DbVisualizer – Tone
DBVisualizer是您用來查詢數據的工具,而不是用於存儲信息的DB2數據庫。數據庫服務器運行的是哪個版本的DB2,以及哪個操作系統?這些信息可能會幫助我們爲您的環境提供最佳答案。 – WarrenT