@TimBiegeleisen你已经打败了我的时间:)…正在研究查询,但当我刷新页面时看到你已经回复了……很棒的工作……!
顺便说一下,我为此写了以下查询….
SELECT r.name Region, IFNULL(ba.fee, 0) banner_revenue, IFNULL(cp.fee, 0) cuisine_revenue, IFNULL(sp.fee, 0) promotions_revenue, (IFNULL(ba.fee, 0) + IFNULL(cp.fee, 0) + IFNULL(sp.fee, 0)) total
FROM regions r
LEFT JOIN (SELECT SUM(sp.fee) fee, re.region_id FROM sponsored_promotions as sp INNER JOIN restaunts as re ON re.id = sp.restaurant_id GROUP BY re.region_id) sp ON r.id=sp.region_id
LEFT JOIN (SELECT IFNULL(SUM(fee),0) fee, region_id FROMcuisine_promotions
GROUP BY region_id) cp ON r.id=cp.region_id
LEFT JOIN (SELECT IFNULL(SUM(fee),0) fee, region_id FROMbanner_ads
GROUP BY region_id) ba ON r.id=ba.region_id