您好:
写的SQL没有经过测试,请您参考
--采购订单插入临时表 总金额负数
SELECT pro.name,cus.name,taxAmount AS 'purSUM',0 AS 'saleSUM',-taxAmount AS 'Total' INTO #t
FROM 采购订单表 pur
LEFT JOIN 项目表 pro ON pro.id=pur.idproject
LEFT JOIN 往来单位表 cus ON cus.id=pur.idpartner
--销售订单表插入临时表 总金额正数
SELECT pro.name,cus.name,0,taxAmount,taxAmount INTO #t
FROM 销售订单表 sale
LEFT JOIN 项目表 pro ON pro.id=sale.idproject
LEFT JOIN 往来单位表 cus ON cus.id=sale.idpartner
--统计
SELECT 项目.name,往来单位.name
,SUM(purSUM) AS '采购总额'
,SUM(saleSUM) AS '销售总额'
,SUM(Total) AS '毛利润'
FROM #t
GROUP BY 项目.name,往来单位.name