Essentially, I need a query which can output something like:
+------------+-------+
| date | count |
+------------+-------+
| 2020-09-30 | 10 |
| 2020-09-29 | 3 |
| 2020-09-28 | 0 |
| 2020-09-27 | 6 |
| 2020-09-26 | 0 |
| 2020-09-25 | 5 |
| 2020-09-24 | 3 |
+------------+-------+
I know other questions ask something similar but none of the ones I have seen output 0 anything if the count is 0. They do this instead:
+------------+-------+
| date | count |
+------------+-------+
| 2020-09-30 | 10 |
| 2020-09-29 | 3 |
| 2020-09-27 | 6 |
| 2020-09-25 | 5 |
| 2020-09-24 | 3 |
+------------+-------+
Best Answer
The most straightforward approach is to use a date table with all possible dates, then OUTER APPLY to get your hit count for each date, where appropriate.
Something like this:
Here's a script to build and fill your date table: