我从nc的数据库抽取相关数据在帆软里做资产负债表,普通的科目累计还好,但是涉及到一些辅助项混合运算的时候我就做不出来了,虽然我能算出单独科目的辅助余额,但是无法做混合运算,我好奇nc是不是其实有保存辅助余额表的数据库表格的?因为我是直接从凭证余额来按照取数逻辑算的,这样不仅只能算一个,而且耗时非常久。求各位大佬帮帮忙。 下面是我的sql查询 with tab as( select detail.yearv,detail.adjustperiod,(case when supplier.name<>'' then '客商:'+supplier.name when psndoc.name<>'' then '人员档案:'+psndoc.name end) docfree,supplier.pk_cust_sup, sum(localdebitamount) localdebitamountsum,sum(localcreditamount) localcreditamountsum,sum(localdebitamount)-sum(localcreditamount) dcdifference from gl_detail detail left join gl_docfree1 docfree on docfree.assid=detail.assid left join bd_psndoc psndoc on psndoc.pk_psndoc=docfree.f2 left join bd_cust_supplier supplier on supplier.pk_cust_sup=docfree.f4 where detail.discardflagv='N' and detail.pk_accountingbook='${pk_accountingbook}' and detail.yearv='${year}' and detail.accountcode like '${accountcode}%' group by detail.yearv,detail.adjustperiod,supplier.name,psndoc.name,supplier.pk_cust_sup ), dcadd as( select a.yearv,a.adjustperiod,a.docfree,a.pk_cust_sup,sum(b.dcdifference) dcadd,(case when sum(b.dcdifference)>0 then '借' when sum(b.dcdifference)<0 then '贷' when sum(b.dcdifference)=0 then '平' end) direction from tab a inner join tab b on a.pk_cust_sup=b.pk_cust_sup where b.adjustperiod<=a.adjustperiod and a.pk_cust_sup=b.pk_cust_sup group by a.yearv,a.adjustperiod,a.docfree,a.pk_cust_sup ) select sum(dcadd) dcadd from dcadd a where adjustperiod=(select max(adjustperiod) from dcadd b where a.docfree=b.docfree and b.pk_cust_sup=a.pk_cust_sup and adjustperiod<='${adjustperiod}' and a.direction='借') ; |