select ${IF(LEN($AREA)>0,"地市,","")} ${IF(LEN($XMFL)>0,"项目类,","")} SUM(case when 周期='1' then [本币金额] else 0 end) as [第一周], SUM(case when 周期='2' then [本币金额] else 0 end) as [第二周], SUM(case when 周期='3' then [本币金额] else 0 end) as [第三周], SUM(case when 周期='4' then [本币金额] else 0 end) as [第四周], SUM(case when 周期='5' then [本币金额] else 0 end) as [第五周], SUM(case when 周期='6' then [本币金额] else 0 end) as [第六周], (select SUM(case when [科目描述]<> '未核销收款' then 本币余额 else 0 end) as [本币余额] from 应收预收账龄余额表 B where left([科目],4)='1131' and 来源='应收账款' and 日期='2023-02-23' AND A.地市=B.地市 AND A.项目类=B.项目段 ) as bbye, (SELECT SUM(case when [地市]<> '未知' then 期末余额 else 0 end) as [期末余额] from 账户组合余额表 C where 会计要素='收入' and 日期='2023-02-22' and 地市<>'未知' AND A.地市=C.地市 AND A.项目类=C.项目类 ) as qmye from [收款明细表] A WHERE 日期='2023-02-21' ${IF(LEN(AREA)>0," AND 地市 in ('"+AREA+"')","")} ${IF(LEN(XMFL)>0," AND 项目类 in ('"+XMFL+"')","")} ${IF(LEN(XMFL)>0&&LEN(AREA)>0," group by 地市,项目类","")} ${IF(LEN(XMFL)>0&&LEN(AREA)=0," group by 项目类","")} ${IF(LEN(XMFL)=0&&LEN(AREA)>0," group by 地市","")} |