给供应商预付的时候不能只看余额,还应当看应收应付金额,所反应的真实余额应当为ye+ysyfje


所以供应商里真实余额应当为

select c.rq,c.danwbh,c.dwmch,c.ye from

(select rq,danwbh,dwmch,ye from

(select a.ye+a.ysyfje as ye,a.dwbh,a.rq,a.djbh,b.dwmch,b.danwbh,row_number() over (PARTITION BY a.dwbh order by rq desc,plh desc) row from wlzhk a,mchk b where a.dwbh=b.dwbh and a.rq<=getdate() and fx='进') t

where row=1 

) c

order by c.danwbh