WITH PERSONRANK AS ( SELECT REALSALERID, RANK () OVER ( ORDER BY RATE DESC ) PERSONRANK FROM( A AS( SELECT REALSALERID, REALSALERNAME, SUM (ASSIGNLOTGROSS) LOTGROSS FROM F_SALES_VIEW WHERE TO_CHAR(CREDATE,'YYYY-MM-DD') BETWEEN SUBSTR('2016-12-31',0,4)||'-01-01' AND '2016-12-31' AND REALSALERID in ( SELECT WORKCODE FROM DIM_PERSON WHERE OADEPTID IN ( SELECT OADEPTID FROM DIM_PERSON WHERE PERSONID='NB0046' )) GROUP BY REALSALERID, REALSALERNAME ), B AS ( SELECT EMPLOYEEID, SUM (DEBIT) DEBITL FROM F_FINANCE_COST WHERE TO_CHAR(CREDATE,'YYYY-MM-DD') BETWEEN SUBSTR('2016-12-31',0,4)||'-01-01' AND '2016-12-31' AND EMPLOYEEID in ( SELECT WORKCODE FROM DIM_PERSON WHERE OADEPTID IN ( SELECT OADEPTID FROM DIM_PERSON WHERE PERSONID='NB0046' )) GROUP BY EMPLOYEEID ) SELECT REALSALERID, REALSALERNAME, ROUND (CASE DEBITL WHEN 0 THEN 0 ELSE LOTGROSS / DEBITL END,2) RATE FROM A LEFT JOIN B ON A .REALSALERID = B .EMPLOYEEID ) ) SELECT PERSONRANK AS 名次 FROM PERSONRANK WHERE REALSALERID='NB0046' 问题大概是出在FROM 后面,就是不知道怎么解决 |