SELECT ddkh, sum(hz - sjsk) AS syhk FROM (SELECT (SELECT name FROM bd_customer@ncc0614 WHERE pk_customer = a.ccustomerid) AS ddkh, --订单客户 substr(b.dbizdate, 0, 7) AS ckrq, --入库日期 sum(b.norigtaxmny) AS hz, --货值 CASE WHEN sum(c.money_cr) IS NULL THEN 0 ELSE sum(c.money_cr) END AS sjsk --实际收款 FROM ic_saleout_h@ncc0614 a LEFT JOIN ic_saleout_b@ncc0614 b ON a.cgeneralhid = b.cgeneralhid LEFT JOIN so_custaccountdetail@ncc0614 c ON b.cgeneralbid = c.cgeneralbid WHERE a.dr = 0 AND b.dr = 0 AND c.dr = 0 GROUP BY a.ccustomerid, substr(b.dbizdate, 0, 7) ORDER BY substr(b.dbizdate, 0, 7)) WHERE 1=1 ${if(len(p1) == 0,"","and ddkh = '" +p1+ "'")} ${if(len(p4) == 0,"","and ckrq < " + substr(p4,0,7) + "")} GROUP BY ddkh参数如下所示:报错如下所示: