mysql多表联合查询并统计

推广地点表promotion_addr字段:name,id

电话报竣表unicom_record字段:date, sheet_id(关联sheet表id)

报单表sheet字段:id,promotion_addr_id(关联promotion_addr表id)

要求统计某个月已报竣各推广地点的推广个数;

 

SELECT
p.name, count(*)
FROM
unicom_record AS ur

Left Join sheet AS s ON ur.sheet_id = s.id
Left Join promotion_addr AS p ON s.promotion_addr_id = p.id
WHERE
ur.status =  'COMPLETE' AND
ur.`date` >=  '2010-03-01' AND
ur.`date` <  '2010-04-01'
GROUP BY
p.id

(或使用between and语句)

你可能感兴趣的:(MySQL)