उपयोग (अद्यतन #2)
SELECT
a.a_datetm as 'October',
IFNULL(p.a1,0) as 'Auth1',
IFNULL(p.a2,0) as 'Auth2',
IFNULL(p.a50,0) as 'Auth50'
FROM
(
SELECT CONCAT (day(X.a_date), '-1') AS a_datetm
FROM all_date X
WHERE X.a_date between '2011-10-01' and '2011-10-31'
UNION ALL
SELECT CONCAT (day(Y.a_date), '-2') AS a_datetm
FROM all_date Y
WHERE Y.a_date between '2011-10-01' and '2011-10-31'
UNION ALL
SELECT CONCAT (day(Z.a_date), '-3') AS a_datetm
FROM all_date Z
WHERE Z.a_date between '2011-10-01' and '2011-10-31'
) a
LEFT OUTER JOIN
(
SELECT
CONCAT (day(wp.post_date), (CASE WHEN (TIME(wp.post_date) < '14:31:00') THEN '-1' WHEN (TIME(wp.post_date) BETWEEN '14:31:00' AND '18:15:59') THEN '-2' ELSE '-3' END )) AS a_datetm,
sum(case when wp.post_author = '1' then 1 else 0 end) as a1,
sum(case when wp.post_author = '2' then 1 else 0 end) as a2,
sum(case when wp.post_author = '50' then 1 else 0 end) as a50,
count(*) as 'All Auths'
FROM wp_posts wp
WHERE wp.post_type = 'post'
AND wp.post_date between '2011-10-01' and '2011-10-31 23:59:59'
GROUP BY CONCAT (day(wp.post_date), (CASE WHEN (TIME(wp.post_date) < '14:31:00') THEN '-1' WHEN (TIME(wp.post_date) BETWEEN '14:31:00' AND '18:15:59') THEN '-2' ELSE '-3' END ))
) p
ON a.a_datetm = p.a_datetm
ORDER BY a.a_datetm ASC;