I have data that looks like this:
| DateTime | Category | Total |
|------------------|----------|-------|
| 3/23/18 9:00 AM | Bork | 1 |
| 3/23/18 9:15 AM | Arf | 2 |
| 3/23/18 9:30 AM | Bork | 1 |
| 3/23/18 9:45 AM | Arf | 2 |
| 3/23/18 10:00 AM | Bork | 1 |
| 3/23/18 10:15 AM | Arf | 2 |
| 3/23/18 10:30 AM | Bork | 1 |
| 3/23/18 10:45 AM | Arf | 2 |
| 3/23/18 11:00 AM | Bork | 1 |
| 3/23/18 11:15 AM | Arf | 2 |
| 3/23/18 11:30 AM | Bork | 1 |
| 3/23/18 11:45 AM | Arf | 2 |
| 3/23/18 12:00 PM | Bork | 1 |
| 3/23/18 12:15 PM | Arf | 2 |
| 3/23/18 12:30 PM | Bork | 1 |
| 3/23/18 12:45 PM | Arf | 2 |
And I want to sum by hour and keep the categories separate like this:
| Hour | Borks | Arfs |
|------|-------|------|
| 9 | 2 | 4 |
| 10 | 2 | 4 |
| 11 | 2 | 4 |
| 12 | 2 | 4 |
I know how to sum data by hour already... I use a query like this:
SELECT DatePart("h", DateTime), SUM(Total)
FROM Events
GROUP BY DatePart("h", DateTime), DateAdd("d", 0, DateDiff("d", 0, DateTime))
But how do I sum the categories into separate columns, and how do I name the columns in the output too?
Also, how do I make sure all hours are represented in the results, even if they have no data in the source? For example, it would have the hour listed and the total = 0.