SQL/DB2 将行连接成一个字段 (DB2)
SQL/DB2 concatenate rows into one field (DB2)
尝试将 table 中的值与内部联接连接起来,这可能吗,示例代码已附上。
如果我删除 CM.CMCSNM 列,代码将正常工作
SELECT trim(CM.CMCSNM), CALLLOGP.CHSTKY,
SUBSTR(xmlserialize(xmlagg(xmltext(CONCAT( ', ',CALLLOGP.CHORD#))) as
VARCHAR(1024)), 3) AS Batches
FROM LS3DTA100A.CALLLOGP CALLLOGP inner join LS3DTA100A.CM CM on
CM.CMSTKY=CALLLOGP.CHSTKY
WHERE (CALLLOGP.CHOPENBY<>'')
AND (CALLLOGP.CHCLOSDT=0)
AND (CALLLOGP.CHACKNDT=0)
AND (CALLLOGP.CHUPDATE=0)
AND (CALLLOGP.CHCOMMENTS Like '%FRAME OOS%')
AND (CALLLOGP.CHSTKY Like '00%')
GROUP BY CALLLOGP.CHSTKY
错误消息是 SQL 错误 [42803]:[SQL0122] 列 CMCSNM 或 SELECT 列表中的表达式无效。
SQL0122N A SELECT statement with no GROUP BY clause contains a column
name or expression and a column function in the SELECT clause, or
a column name or expression is contained in the SELECT clause but
not in the GROUP BY clause.
您需要将 trim(CM.CMCSNM) 作为 GROUP BY 的一部分。例如:
GROUP BY trim(CM.CMCSNM), CALLLOGP.CHSTKY
尝试将 table 中的值与内部联接连接起来,这可能吗,示例代码已附上。
如果我删除 CM.CMCSNM 列,代码将正常工作
SELECT trim(CM.CMCSNM), CALLLOGP.CHSTKY,
SUBSTR(xmlserialize(xmlagg(xmltext(CONCAT( ', ',CALLLOGP.CHORD#))) as
VARCHAR(1024)), 3) AS Batches
FROM LS3DTA100A.CALLLOGP CALLLOGP inner join LS3DTA100A.CM CM on
CM.CMSTKY=CALLLOGP.CHSTKY
WHERE (CALLLOGP.CHOPENBY<>'')
AND (CALLLOGP.CHCLOSDT=0)
AND (CALLLOGP.CHACKNDT=0)
AND (CALLLOGP.CHUPDATE=0)
AND (CALLLOGP.CHCOMMENTS Like '%FRAME OOS%')
AND (CALLLOGP.CHSTKY Like '00%')
GROUP BY CALLLOGP.CHSTKY
错误消息是 SQL 错误 [42803]:[SQL0122] 列 CMCSNM 或 SELECT 列表中的表达式无效。
SQL0122N A SELECT statement with no GROUP BY clause contains a column
name or expression and a column function in the SELECT clause, or
a column name or expression is contained in the SELECT clause but
not in the GROUP BY clause.
您需要将 trim(CM.CMCSNM) 作为 GROUP BY 的一部分。例如:
GROUP BY trim(CM.CMCSNM), CALLLOGP.CHSTKY