SELECT 客户编码,客户名称,ISNULL(合计发出金额,0) AS合计发出金额,ISNULL(合计回款金额,0) AS 合计回款金额,ISNULL(合计发票金额,0) AS 合计发票金额 FROM a LEFT JOIN (SELECT 客户编号,SUM(发出金额) AS 合计发出金额 FROM b GROUP BY 客户编号) btmp ON a.客户编号=btmp.客户编号 LEFT JOIN (SELECT 客户编号,SUM(回款金额) AS 合计回款金额 FROM c
GROUP BY 客户编号) ctmp ON a.客户编号=ctmp.客户编号 LEFT JOIN (SELECT 客户编号,SUM(发票金额) AS 合计发票金额 FROM d GROUP BY 客户编号) dtmp ON a.客户编号=dtmp.客户编号
(注意以上语句是用于SQL server的,如果用于Foxpro9则把上述语句中ISNULL(合计发出金额) AS 合计发出金额,改为IIF(ISNULL(合计发出金额),0,合计发出金额) AS 合计发出金额 ,其它两个ISNULL(......)字段也作相应修改就行了。)
[此贴子已经被作者于2016-12-4 19:59编辑过]