select * from ( select A.YPNM00,A.YPMC00,round(sum(CSL000 * GJDJ00 /ZHL000),2) ZJE000,A.QLDW00,A.YPGG00 from VW_YF_BRYY A,BM_YD0000 B where A.YPNM00=B.YPNM00 and B.KSSJB0=0 and A.SRRQ00 between '20201001' and '20201031' group by A.YPNM00,A.YPMC00,A.QLDW00,A.YPGG00 having sum(CSL000 * GJDJ00 /ZHL000) >0 order by sum(CSL000 * GJDJ00 /ZHL000) desc ) where rownum<=50 select decode(substr(CFLB00,0,2),'门诊','门诊','住院') MZZY00, KB0000,GHZYH0,BRXM00,XB0000,NL0000,YSXM00, round(sum(CSL000 * GJDJ00 / ZHL000),2) YPSYJE from VW_YF_BRYY where YPNM00=11186 and SRRQ00 between '20201001' and '20201031' group by CFLB00,KB0000,GHZYH0,BRXM00,NL0000,XB0000,YSXM00 order by KB0000