试试这个:
SELECT
`date`,
SUM(IF(za_type=1,nb,0)) as sum1,
SUM(IF(za_type=2,nb,0)) as sum2,
SUM(IF(za_type=3,nb,0)) as sum3
FROM (
SELECT b.`date`,1 as za_type, COUNT(*) as nb FROM `subtable1` AS b WHERE b.`date` IN ('31-05-2013','30-05-2013','29-05.2013') UNION
SELECT c.`date`,2 as za_type, COUNT(*) as nb FROM `subtable2` AS c WHERE c.`date` IN ('31-05-2013','30-05-2013','29-05.2013') UNION
SELECT d.`date`,3 as za_type, COUNT(*) as nb FROM `subtable3` AS d WHERE d.`date` IN ('31-05-2013','30-05-2013','29-05.2013')
) as tmp
GROUP BY
`date`
更新:如果您需要过去 30 天,您可以添加此条件date >= NOW() - INTERVAL 30 DAY
而不是date IN (..)
UPDATE2:使用新要求(查询是最近 3 天):
SELECT
za_day,
(SELECT COUNT(*) FROM subtable1 s WHERE s.date = za_day) as sum1,
(SELECT COUNT(*) FROM subtable2 s WHERE s.date = za_day) as sum2,
(SELECT COUNT(*) FROM subtable3 s WHERE s.date = za_day) as sum3
FROM (
SELECT DATE(NOW()) - INTERVAL 1 DAY as za_day UNION
SELECT DATE(NOW()) - INTERVAL 2 DAY as za_day UNION
SELECT DATE(NOW()) - INTERVAL 3 DAY as za_day
) as td