DB2 With语句递归
WITH T1 (T11 , T22 , T33 , T44) AS (SELECT TASKID , REPLY , ROWNUMBER () OVER (PARTITION BY TASKID) , ROWNUMBER () OVER (PARTITION BY TASKID) AS T4 FROM RT_CALLTASKRECDT) , T3 (S1 , S2 , S3 , S4) AS (SELECT T11 , CAST (T22 AS VARCHAR (100)) , T33 , T44 FROM T1 WHERE T33 = 1 AND T44 = 1 UNION ALL SELECT A.S1 , CAST (A.S2 || ',' || B.T22 AS VARCHAR (100)) , A.S3 + 1 , A.S4 FROM T3 A , T1 B WHERE A.S1 = B.T11 AND A.S3 = B.T44 - 1) SELECT S1 , S2 FROM T3 X WHERE X.S3 = (SELECT MAX (S3) FROM T3 Y WHERE X.S1 = Y.S1);