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

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。