日期:2014-05-16  浏览次数:20774 次

DB2 删除表中业务重复数据
DELETE
FROM
    hnjavadb.T_BPM_PERM_OPT
WHERE
    T_ID IN
    (
        SELECT
            T_ID
        FROM
            hnjavadb.T_BPM_PERM_OPT o ,
            (
                SELECT
                    *
                FROM
                    (
                        SELECT
                            BUKRS,
                            PROCID ,
                            TASKID,
                            ROLEID,
                            TASKBUKRS,
                            COUNT(T_ID) AS NUMBER,
                            MIN(T_ID)   AS minID
                        FROM
                            hnjavadb.T_BPM_PERM_OPT
                        GROUP BY
                            BUKRS,
                            PROCID ,
                            TASKID,
                            ROLEID,
                            TASKBUKRS
                        HAVING
                            COUNT(T_ID) >1
                        ORDER BY
                            NUMBER DESC)) AS b
        WHERE
            o.bukrs = b.bukrs
        AND o.PROCID = b.PROCID
        AND o.TASKID = b.TASKID
        AND o.ROLEID = b.ROLEID
        AND o.TASKBUKRS = b.TASKBUKRS
        AND o.T_ID > b.minID)