timescaledb or postgresql aggregation by getting time difference between two events
I collect device ON/OFF events in a timeseries table. Following is a sample data. time_stamp state 2023-10-04 10:05:53 0 2023-10-04 10:15:58 1 2023-10-04 10:30:59 0 2023-10-04 10:40:00 1 2023-10-04 10:55:01 0 2023-10-04 11:05:03 1 2023-10-04 11:35:36 0 2023-10-04 11:40:39 1…