各位,我需要根据pbvid汇总每条pbvid对应的isum值,然后需要分别用iamount(同一个值)减去汇总的这个值,具体的语句应该如何描述,这个语句具体怎么改? select ta.iamount+isum-ta.iapplyamt as fsum,* from (select app.dVouchDate,apps.iApplyAmt,ap.cexch_name,app.cSSCode,app.cVouchID,app.cvouchtype,app.cDigest,app.dCloseDate,app.PID,ap.iamount,v.cVenName,v.cVenCode,ss.cSSNamefrom Ap_Vouch ap,AP_ApplyPayVouch app,AP_ApplyPayVouchs apps,Vendor v,SettleStyle sswhere ap.cFlag=app.cFlag and ap.bStartFlag=1 and app.PID=apps.PID and app.cSSCode=ss.cSSCode and ap.cDwCode=v.cvencode) tafull join(select pb.cAuditDate,pbs.iSum,pb.cPBVMemo,pbs.cPZNum,pb.cVenCode,pb.cPBVVerifier,cPBVMaker,pb.dGatheringDate,pb.cOrderCode,pb.cPBVCode,pb.cPBVBillType,pb.cBusType,pbs.PBVIDfrom PurBillVouch pb,PurBillVouchs pbs,Vendor vwhere pbs.PBVID=pb.PBVID and pb.cVenCode=v.cvencode) tbon ta.cVenCode=tb.cVenCodewhere dVouchDate is not null |