我想联接三个表,并希望同时进行汇总。
SELECT t1.id AS in_id,t2.id AS out_id,t1.thickness,t1.paper_quality_id,t1.paper_brand_id,t1.paper_size_id,(t1.total_sheets) AS in_sheets,t1.inward_sheet, t2.out_reams,t2.out_sheets
FROM
(SELECT *, sum(api_inwardinventory.total_sheets) AS inward_sheet FROM api_inwardinventory WHERE api_inwardinventory.account_access_key_id=1 AND api_inwardinventory.inward_date BETWEEN '2019-05-01 04:24:05.0001' AND
'2019-05-18 04:24:05.00000' GROUP BY api_inwardinventory.account_access_key_id,api_inwardinventory.paper_quality_id,api_inwardinventory.paper_brand_id,
api_inwardinventory.paper_size_id,api_inwardinventory.thickness)
AS t1
LEFT JOIN
(SELECT *, sum(api_outwarditems.reams) AS out_reams,sum(api_outwarditems.sheets) AS out_sheets FROM api_outwarditems WHERE api_outwarditems.account_access_key_id=1 AND api_outwarditems.date_outward BETWEEN '2019-05-01 04:24:05.0001' AND
'2019-05-18 04:24:05.00000' GROUP BY api_outwarditems.account_access_key_id,api_outwarditems.paper_quality_id,api_outwarditems.paper_brand_id,api_outwarditems.paper_size_id,
api_outwarditems.thickness)
AS t2
ON t1.account_access_key_id=t2.account_access_key_id AND t1.paper_quality_id=t2.paper_quality_id AND t1.paper_brand_id=t2.paper_brand_id AND t1.paper_size_id=t2.paper_size_id
AND t1.thickness=t2.thickness
想要合并此表
SELECT api_inwardinventory.account_access_key_id,api_inwardinventory.id,api_inwardinventory.paper_quality_id,api_inwardinventory.paper_brand_id,
api_inwardinventory.paper_size_id,api_inwardinventory.thickness,api_inwardinventory.total_sheets
FROM api_inwardinventory
WHERE api_inwardinventory.account_access_key_id=1 AND api_inwardinventory.inward_date <= '2019-05-30 04:24:05.0001'
GROUP BY api_inwardinventory.paper_quality_id,api_inwardinventory.paper_size_id,api_inwardinventory.paper_brand_id,api_inwardinventory.thickness