SELECT ${IF(LEN($AREA)>0,"地市,","")}${IF(LEN($XMFL)>0,"项目段,","")}(-),(-),(-),(-),(-),(-),(-),(-),(-),(-),(-),(-),(-)FROM(SELECT * FROM(SELECT ${IF(LEN($AREA)>0,"地市,","")}${IF(LEN($XMFL)>0,"项目段,","")}SUM(case when 科目描述 like'%实际%' then 本币余额 else 0 end)/10000 as ,SUM(case when 科目描述 like'%暂估%' then 本币余额 else 0 end)/10000 as ,SUM(case when <> '未核销收款' then 本币余额 else 0 end)/10000 as ,SUM(case when <> '未核销收款' then else 0 end)/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end) /10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end)/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )as FROM 应收预收账龄余额表 where left(,4)='1131' and 来源='应收账款' and 日期='2023-03-23' and 公司段说明='分公司' ${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 地市","")}) a left JOIN ( SELECT${IF(LEN($AREA)>0,"地市,","")}${IF(LEN($XMFL)>0,"项目段,","")}SUM(case when 科目描述 like'%实际%' then 本币余额 else 0 end)/10000 as ,SUM(case when 科目描述 like'%暂估%' then 本币余额 else 0 end)/10000 as ,SUM(case when <> '未核销收款' then 本币余额 else 0 end)/10000 as ,SUM(case when <> '未核销收款' then else 0 end)/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end) /10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end)/10000 as ,SUM(case when <> '未核销收款' then else 0 end )/10000 as ,SUM(case when <> '未核销收款' then else 0 end )as FROM 应收预收账龄余额表 where left(,4)='1131' and 来源='应收账款' and 日期='2023-02-27' and 公司段说明='分公司' ${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 地市","")}) b on ${IF(LEN(XMFL)>0&&LEN(AREA)>0," a.地市=b.地区,a.项目段=b.项目类","")} ${IF(LEN(XMFL)>0&&LEN(AREA)=0," group by a.项目段=b.项目类","")} ${IF(LEN(XMFL)=0&&LEN(AREA)>0," group by a.地市=b.地区","")})main