我在本期节余里面没有加起初数,你加上起初数就行了。
select vipzh.vipkh,vipzh.xm,vipzh.addr,isnull(tem1.qcs,0),isnull(tem2.bqzj,0),isnull(tem2.bqjs,0),isnull(tem2.bqjy+tem1.qcs,0) from vipzh
left join(select vipkh,sum(zjjf)-sum(jsjf) as qcs from jfb where fsrq<@startdate group by vipkh) tem1 on vipzh.vipkh=tem1.vipkh
left join(select vipkh,sum(zjjf) as bqzj,sum(jsjf) as bqjs,sum(zjjf)-sum(jsjf) as bqjy from jfb where fsrq between @startdate and @enddate group by vipkh) tem2 on vipzh.vipkh=tem2.vipkh;