select js.VBILLNO,js.dbilldate,js.startdate,js.enddate,js.nsummny,skb.kxlx||skb.vname fyxm,sum(nvl(skb.nrevmny,0)) skje,js.user_name from pr_cr_cashbillcalc_b jsd_b
left join
(select jsd.vbillno,jsd.dbilldate,jsd.startdate,jsd.enddate,jsd.nsummny,yh.user_name,jsd.pk_cashbillid from pr_cr_cashbillcalc jsd
left join sm_user yh
on jsd.VOPERATORID=yh.cuserid
where nvl(jsd.dr,0)=0 and jsd.pk_corp=#LoginCorp#) js
on jsd_b.pk_cashbillid=js.pk_cashbillid
left join
(
select case
when rfb.nrevmny<0 then
*退*||decode(rfb.frevtype,3,*押金*,null)
when rfb.nrevmny>=0 then
*收*||decode(rfb.frevtype,3,*押金*,null)
else
null
end as kxlx,fyxm.vname,rfb.nrevmny,rfb.pk_revfareid from pr_cr_revfare_b rfb
left join pr_bd_faretype fyxm
on rfb.pk_faretypeid=fyxm.pk_faretypeid
where nvl(rfb.dr,0)=0 and rfb.frevtype<>2 and rfb.frevtype<>7
) skb
on jsd_b.VLASTBILLID=skb.pk_revfareid
where nvl(jsd_b.dr,0)=0 and (js.dbilldate>=#ksrq# and js.dbilldate<=#jzrq# or #ksrq# is null) and (js.VBILLNO=#yjdh# or #yjdh# is null) and (js.user_name=#yjr# or #yjr# is null) group by js.VBILLNO, js.dbilldate, js.startdate, js.enddate,js.nsummny,skb.kxlx||skb.vname, js.user_name
left join
(select jsd.vbillno,jsd.dbilldate,jsd.startdate,jsd.enddate,jsd.nsummny,yh.user_name,jsd.pk_cashbillid from pr_cr_cashbillcalc jsd
left join sm_user yh
on jsd.VOPERATORID=yh.cuserid
where nvl(jsd.dr,0)=0 and jsd.pk_corp=#LoginCorp#) js
on jsd_b.pk_cashbillid=js.pk_cashbillid
left join
(
select case
when rfb.nrevmny<0 then
*退*||decode(rfb.frevtype,3,*押金*,null)
when rfb.nrevmny>=0 then
*收*||decode(rfb.frevtype,3,*押金*,null)
else
null
end as kxlx,fyxm.vname,rfb.nrevmny,rfb.pk_revfareid from pr_cr_revfare_b rfb
left join pr_bd_faretype fyxm
on rfb.pk_faretypeid=fyxm.pk_faretypeid
where nvl(rfb.dr,0)=0 and rfb.frevtype<>2 and rfb.frevtype<>7
) skb
on jsd_b.VLASTBILLID=skb.pk_revfareid
where nvl(jsd_b.dr,0)=0 and (js.dbilldate>=#ksrq# and js.dbilldate<=#jzrq# or #ksrq# is null) and (js.VBILLNO=#yjdh# or #yjdh# is null) and (js.user_name=#yjr# or #yjr# is null) group by js.VBILLNO, js.dbilldate, js.startdate, js.enddate,js.nsummny,skb.kxlx||skb.vname, js.user_name