报表查询:收费汇总表
收费汇总表,需要考虑的是如何避免重复数据的问题
报表查询sql
SELECT * from ( SELECT ROWNUM AS ID, TT.*, NVL(SF.JFJE,0) JFJE,--取收费表的交费金额,其他暂不考虑 TRUNC(QFJE1/NVL(SF.COUNT,1),1)+NVL(SF.JFJE,0) as YSJE,--欠费+交费=应收 NVL(SF.JFRQ,?) AS JFRQ,--未交费的(原无交费日期),赋一个交费日期,包含在查询范围内 TRUNC(SFMJ1/NVL(SF.COUNT,1),2) SFMJ,--有多笔交费记录的,统计时会统计上,这里除以个数,最后统计和为sfmj TRUNC(QFJE1/NVL(SF.COUNT,1),1) QFJE--欠费金额,防止多笔交费后仍有欠费 FROM ( SELECT SF_JMYH_T.YHBM AS YHBM, SF_JMYH_T.YHBH AS YHBH, SF_JMYH_T.YHMC AS YHMC, SF_JMYH_T.FGS AS FGS , SF_JMYH_T.RLZ AS RLZ, SF_JMYH_T.XQ AS XQ , SF_JMJS_T.CNQ AS CNQ, SF_JMJS_T.SFMJ AS SFMJ1, /*只适用单笔交费的,不合理*/ --SF_JMJS_T.YSJE +SF_JMJS_T.JBCNFYS AS YSJE, --SF_JMJS_T.SFJE+SF_JMJS_T.JBCNFSF+SF_JMJS_T.HJJE -SF_JMJS_T.YJJE AS JFJE, SF_JMJS_T.QFJE +SF_JMJS_T.JBCNFQF AS QFJE1 FROM SF_JMYH_T , SF_JMJS_T WHERE (SF_JMYH_T.ZF=0) AND (SF_JMJS_T.ZF=0) AND (SF_JMJS_T.YHBH=SF_JMYH_T.YHBH) and (SF_JMJS_T.CNQ= ? or ? is null ) and (SF_JMYH_T.FGS = ? or ? is null ) and (SF_JMYH_T.rlz = ? or ? is null ) and (SF_JMYH_T.xq = ? or ? is null ) and (SF_JMYH_T.yhlb = ? or ? is null ) ) TT,(select * from sf_jmsf_t,(select yhbh yhbh2,count(yhbh) COUNT from sf_jmsf_t where zf=0 and cnq= ? group by yhbh) SFCOUNT where sf_jmsf_t.zf=0 and sf_jmsf_t.yhbh =SFCOUNT.yhbh2(+)) SF WHERE TT.cnq=sf.cnq(+) and TT.yhbh =sf.yhbh(+)) TTT /*SF统计 收费表字段和同一个yhbh在同一个cnq出现的个数(多个即为多次交费)*/ WHERE (TTT.jfrq>= ? ) and (TTT.jfrq<= ? )
查询界面如下
数据库查询