I have a Postgres database with a ticket table. Each ticket has a 'created_at' timestamp and a 'resolved_at' timestamp. I would eventually like to create a time series visualization to track the number of 'unresolved' tickets over time.
For example, I would like to look at the last 24 hours and see how many tickets were unresolved at the end of each hour, i.e. how many were created_at < "point-in-time" AND resolved_at > "point-in-time".
I have no idea how I begin to query this sort of information. How would I reference the multiple "point-in-time values" in my query?
Example setup:
CREATE TABLE tickets (
id int,
created_at timestamp,
resolved_at timestamp
);
INSERT INTO tickets VALUES
(1, '2019-10-01 01:30:00'::timestamp, '2019-10-01 05:45:00'::timestamp),
(2, '2019-10-01 02:30:00'::timestamp, '2019-10-01 05:45:00'::timestamp),
(3, '2019-10-01 03:30:00'::timestamp, '2019-10-01 05:45:00'::timestamp),
(4, '2019-10-01 04:30:00'::timestamp, '2019-10-01 05:45:00'::timestamp),
(5, '2019-10-01 05:30:00'::timestamp, '2019-10-01 05:45:00'::timestamp);
I can see from looking at this data that at 01:00 we have 0 unresolved, at 02:00 1 unresolved (ticket 1), ... , 05:00 4 unresolved, 06:00 0 unresolved (all the tickets get resolved by 05:45). I'm not sure how to query for this information