對db2結果集加編號

 SELECT DISTINCT
    r.APPR_NO,
    r.RPT_NO,
    REPLACE(SUBSTR(CHAR(r.APPR_TIME),1,10),'/','-') AS APPR_TIME,
    r.APPR_RESULT,
    r.appr_person,
    u.USR_NAME,
    o.ORG_NAME,
    j.JOB_NAME,
    r.APPR_OPINION,
    CASE
        WHEN rt.upt_user !=''
        AND rt.upt_user IS NOT NULL
        THEN '1'
        ELSE '0'
    END upt_user,
    ROW_NUMBER() OVER() as ROW_NO
FROM
    CMS.RPT_APPR r
LEFT JOIN
    CMS.USERINFO u
ON
    u.USR_ID=r.APPR_PERSON
LEFT JOIN
    CMS.ORGAN o
ON
    o.ORG_NO = u.ASPT_ORGNO
LEFT JOIN
    CMS.JOBINFO j
ON
    j.JOB_NO = u.JOB_NO
LEFT JOIN
    rptacy rt
ON
    (
        rt.rpt_no=r.rpt_no
    AND r.APPR_PERSON=rt.upt_user )
WHERE
    1=1
AND r.APPR_TIME IS NOT NULL

 

 

 

紅色部分就是實現加編號的函數,大家可以嘗試。

你可能感兴趣的:(DB2)