I have a table with a series of date ranges like this:
id, start_date, end_date,
(1, '2022-01-01', '2022-01-31'),
(2, '2022-01-01', '2022-01-05'),
(3, '2022-01-03', '2022-01-06'),
(4, '2022-01-01', '2022-01-01')
I would like to be able to look at each date (from a series) and see how many of these ranges fall into each date. The date series would ideally start from the smallest value in a starting range. But starting from say 1 year ago to now would also be sufficient.
The outcome looking like this:
| Date | Count |
| ---------- | ----- |
| 10/07/2022 | 6 |
| 9/07/2022 | 8 |
| 8/07/2022 | 12 |
| 7/07/2022 | 5 |
We cannot use the generate_series function in Amazon Redshift. So I have generated a series like so which goes back 365 days:
SELECT DATEADD('day', 1-n, (DATE_TRUNC('day', CURRENT_DATE))) AS generated_date
FROM (SELECT ROW_NUMBER() OVER () AS n FROM stl_scan LIMIT 365) n
ORDER BY generated_date DESC
Struggling to implement this generated series into my query.