TERADATA 分页的两种方式

1、SELECT
    Sp_Id spId
    ,Sp_Name Sp_Name
    ,SUM(CASE WHEN Sp_Type='SMS' THEN Sp_Users ELSE 0 END) smsUsers
    ,SUM(CASE WHEN Sp_Type='SMS' THEN Acct_Fee ELSE 0 END) smsIncome
    ,SUM(CASE WHEN Sp_Type='MMS' THEN Sp_Users ELSE 0 END) mmsUsers
    ,SUM(CASE WHEN Sp_Type='MMS' THEN Acct_Fee ELSE 0 END) mmsIncome
    ,SUM(CASE WHEN Sp_Type='WAP' THEN Sp_Users ELSE 0 END) wapUsers
    ,SUM(CASE WHEN Sp_Type='WAP' THEN Acct_Fee ELSE 0 END) wapIncome   
    ,SUM(Acct_Fee) totalIncome
    ,SUM(Sett_Fee) settIncome
    ,(totalIncome-settIncome) profit
    ,row_number() OVER(ORDER BY spId) RN
FROM
    PD_MARTDATA_Z.APP_SP_USERS_INCOME
GROUP BY 1,2
QUALIFY RN >10 AND RN<=20

2、SELECT
    Sp_Id spId
    ,Sp_Name Sp_Name
    ,SUM(CASE WHEN Sp_Type='SMS' THEN Sp_Users ELSE 0 END) smsUsers
    ,SUM(CASE WHEN Sp_Type='SMS' THEN Acct_Fee ELSE 0 END) smsIncome
    ,SUM(CASE WHEN Sp_Type='MMS' THEN Sp_Users ELSE 0 END) mmsUsers
    ,SUM(CASE WHEN Sp_Type='MMS' THEN Acct_Fee ELSE 0 END) mmsIncome
    ,SUM(CASE WHEN Sp_Type='WAP' THEN Sp_Users ELSE 0 END) wapUsers
    ,SUM(CASE WHEN Sp_Type='WAP' THEN Acct_Fee ELSE 0 END) wapIncome   
    ,SUM(Acct_Fee) totalIncome
    ,SUM(Sett_Fee) settIncome
    ,(totalIncome-settIncome) profit
FROM
    PD_MARTDATA_Z.APP_SP_USERS_INCOME
GROUP BY 1,2

QUALIFY RANK(NO_ID DESC) <= #endRecord# AND RANK(NO_ID DESC) > #startRecord#

你可能感兴趣的:(WAP)