Here is where I am at so far with a query. The submitted field is a date/time field that records the time and date a ticket was submitted. The id is a unique identifier for each ticket. I need to count the number of tickets submitted every hour for each day of the year. The table contains all tickets for a single year. For any hours where no tickets were submitted, I need to list a 0 value, which is where I am having a problem.
SELECT DateValue(submitted) AS [date], DatePart("h", submitted) AS [hour], nz(COUNT(id), 0) AS [total_tickets]
FROM table
GROUP BY DateValue(submitted), DatePart("h", submitted);
The results are not what I need:
| date | hour | total_tickets |
|---|---|---|
| 01-Jan-21 | 0 | 1 |
| 01-Jan-21 | 1 | 5 |
| 01-Jan-21 | 2 | 1 |
| 01-Jan-21 | 5 | 1 |
| 01-Jan-21 | 6 | 12 |
| 01-Jan-21 | 8 | 1 |
No tickets were submitted in the hours of 3, 4, & 7, thus no values are included in the results. However, I need those missing hours to be displayed with corresponding 0s in the total_tickets field. I am having a hard time finding a way to do this in Access SQL. Any help would be greatly appreciated.