效果1:
- SELECT 科目,子明细,SUM(借方) AS 上月借方,SUM(贷方) AS 上月贷方,SUM(借方金额) AS 本月借方,SUM(贷方金额) AS 本月贷方 FROM
- (SELECT 科目,子明细,借方金额,贷方金额,NULL AS 借方,NULL AS 贷方 FROM [数据库$] WHERE 0=DATEDIFF("M",记账日期,DATE())
- UNION ALL
- SELECT 科目,子明细,NULL,NULL,借方金额,贷方金额 FROM [数据库$] WHERE 1=DATEDIFF("M",记账日期,DATE()))
- GROUP BY 科目,子明细
复制代码
效果2:
- SELECT 科目,子明细,SUM(借方) AS 上月借方,SUM(贷方) AS 上月贷方,SUM(借方金额) AS 本月借方,SUM(贷方金额) AS 本月贷方,IIF(sum(借方余)>0,SUM(借方余)) AS 借方结余,IIF(SUM(贷方余)>0,SUM(贷方余)) AS 贷方结余 FROM
- (SELECT 科目,子明细,借方金额,贷方金额,NULL AS 借方,NULL AS 贷方,IIF(借方金额,借方金额,0)-IIF(贷方金额,贷方金额,0) AS 借方余,-借方余 AS 贷方余 FROM [数据库$] WHERE 0=DATEDIFF("M",记账日期,DATE())
- UNION ALL
- SELECT 科目,子明细,NULL,NULL,借方金额,贷方金额,IIF(借方金额,借方金额,0)-IIF(贷方金额,贷方金额,0) AS 借方余,-借方余 FROM [数据库$] WHERE 1=DATEDIFF("M",记账日期,DATE()))
- GROUP BY 科目,子明细
复制代码 |