码迷,mamicode.com
首页 > 数据库 > 详细

DB2 With语句递归

时间:2015-02-13 10:11:40      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

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

 

DB2 With语句递归

标签:

原文地址:http://www.cnblogs.com/ShaYeBlog/p/4289726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!