I have the following table in MySQL...
CREATE TABLE `visits` (
`id` int(10) unsigned NOT NULL auto_increment,
`visit` datetime NOT NULL default '0000-00-00 00:00:00',
`bulletin` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
)
Where "visit" is the time a visit occurs, and "bulletin" is the article requested at that time.
I want to know what times are popular with my users, so I have the following query...
SELECT
count(*) as c,
Date_format (visit, '%l%p, %e %b %Y') as e
FROM
`visits`
WHERE 1
AND
date(visit) > date(now() - interval 2 day)
group by e
order by visit desc
Which returns...
c e
4 12PM, 27 Oct 2009
9 11AM, 27 Oct 2009
5 10AM, 27 Oct 2009
2 9AM, 27 Oct 2009
3 4PM, 26 Oct 2009
6 3PM, 26 Oct 2009
16 2PM, 26 Oct 2009
So far so good.
But how do I get the query to return "0" for count and the time for the missing hours? for example, I'd like the results to look something like...
c e
4 12PM, 27 Oct 2009
9 11AM, 27 Oct 2009
5 10AM, 27 Oct 2009
2 9AM, 27 Oct 2009
0 8AM, 27 Oct 2009
0 7AM, 27 Oct 2009
0 6AM, 27 Oct 2009
0 5AM, 27 Oct 2009
0 4AM, 27 Oct 2009
0 3AM, 27 Oct 2009
0 2AM, 27 Oct 2009
0 1AM, 27 Oct 2009
0 12am, 27 Oct 2009
0 11pm, 26 Oct 2009
0 10pm, 26 Oct 2009
0 9pm, 26 Oct 2009
0 8pm, 26 Oct 2009
0 7pm, 26 Oct 2009
0 6pm, 26 Oct 2009
0 5pm, 26 Oct 2009
3 4PM, 26 Oct 2009
6 3PM, 26 Oct 2009
16 2PM, 26 Oct 2009
I could fudge this in the output code when I print the results, but I'd like the query to provide it for me, if possible.