Query help needed - count occurrences per hour

I am trying to create a query that will count the number of times
each value in field/incident occurs in an hour.

Sample Data:
Date_occurred Time_occurred incident
| 2011-03-01 | 08:25:00 | RCCD |
| 2011-03-01 | 08:22:00 | RCCDSAC |
| 2011-03-01 | 08:24:00 | RCCDSAC |
| 2011-03-01 | 08:25:00 | RCCDSAC |
| 2011-03-01 | 08:08:00 | RCCD |
| 2011-03-01 | 08:11:00 | RCCD |
| 2011-03-01 | 08:05:00 | RCCD |
| 2011-03-01 | 08:03:00 | RCCDIM |
| 2011-03-01 | 07:09:00 | RCCDEM |
| 2011-03-01 | 06:29:00 | RCCDIM |
| 2011-03-01 | 06:32:00 | RCCDEM |
| 2011-03-01 | 06:25:00 | RCCDEM |
| 2011-03-01 | 06:16:00 | RCCDEM |
| 2011-03-01 | 05:59:00 | RCCDSAC |
| 2011-03-01 | 06:01:00 | RCCDSAC |
| 2011-03-01 | 06:02:00 | RCCDSAC |
| 2011-03-01 | 06:04:00 | RCCDSAC |
| 2011-03-01 | 06:05:00 | RCCDEM |
| 2011-03-01 | 05:57:00 | RCCDEM |

What I would like the result to look like this:

Hour RCCD# RCCDSAC# RCCDIM# RCCDEM#
08 | 4 | 3 | 1 | 0
07 | 0 | 0 | 0 | 1
06 | 3 | 0 | 1 | 2

I think that I understand how to group by hour but I’m not sure how to get the totals for each incident type for the hour

Any help will be appreciated.

Extract the totals for each incident type like this:

hour incident total

and then create the horizontal layout using PHP (or whatever language you use).

Thank you for your reply

My goal is to get this data for a 24 hour period with a single query. I don’t want to have to query each hour for each incident type.

I do similar queries with other data, not datetime fields, using sum(if()) statements but have not been able to figure out how to do this when grouping by hour.


SELECT 
    HOUR(Time_occurred) AS hourofday
  , incident
  , COUNT(*)
FROM table
WHERE Date_occurred = ...
GROUP BY 
    HOUR(Time_occurred)
  , incident