修改查询3的sql语法为:
SELECT A.NSRSBH, A.月度, [A].[SE之总计]-[B].[SE之总计] AS 发票大于申报
FROM (SELECT 发票.NSRSBH, Format([KPRQ_Q],"yyyymm") AS 月度, Sum(发票.SE) AS SE之总计 FROM 发票 GROUP BY 发票.NSRSBH, Format([KPRQ_Q],"yyyymm")) AS A LEFT JOIN (SELECT 申报.NSRSBH, Format([SSSQ_Q],"yyyymm") AS 月度, Sum(申报.SE) AS SE之总计 FROM 申报 GROUP BY 申报.NSRSBH, Format([SSSQ_Q],"yyyymm")) AS B ON (A.NSRSBH = B.NSRSBH) AND (A.月度 = B.月度)
WHERE ((([A].[SE之总计]-[B].[SE之总计])>0))
问题1(修改了:没有申报的也显示):
SELECT A.NSRSBH, A.月度, [A].[SE之总计]-nz([B].[SE之总计],0) AS 发票大于申报
FROM (SELECT 发票.NSRSBH, Format([KPRQ_Q],"yyyymm") AS 月度, Sum(发票.SE) AS SE之总计 FROM 发票 GROUP BY 发票.NSRSBH, Format([KPRQ_Q],"yyyymm")) AS A LEFT JOIN (SELECT 申报.NSRSBH, Format([SSSQ_Q],"yyyymm") AS 月度, Sum(申报.SE) AS SE之总计 FROM 申报 GROUP BY 申报.NSRSBH, Format([SSSQ_Q],"yyyymm")) AS B ON (A.月度 = B.月度) AND (A.NSRSBH = B.NSRSBH);