I have a table which is having filenames and a number of timestamp ranges for each file for eg as below:
filename mindatetime maxdatetime
monitor_4.dat 2019-04-28 09:00:00 AM 2019-04-29 11:00:00 AM
monitor_4.dat 2019-04-28 11:00:00 AM 2019-04-29 18:00:00 PM
monitor_4.dat 2019-04-28 09:30:00 AM 2019-04-29 23:00:00 PM
monitor_5.dat 2019-04-28 07:00:00 AM 2019-04-28 10:00:00 AM
monitor_5.dat 2019-04-28 02:00:00 PM 2019-04-28 06:00:00 PM
monitor_5.dat 2019-04-28 09:00:00 AM 2019-04-28 03:00:00 PM
monitor_7.dat 2019-04-21 03:06:26.0 AM 2019-05-21 03:06:10.0 AM
monitor_7.dat 2019-05-21 03:06:10.001 AM 2019-05-24 03:06:11.0 AM
monitor_7.dat 2019-06-05 03:06:18.001 AM 2019-06-06 03:06:11.0 AM
monitor_7.dat 2019-05-24 03:06:11.001 AM 2019-06-05 03:06:18.0 AM
monitor_7.dat 2019-05-12 07:00:10.001 AM 2019-05-13 10:00:10.000 AM
monitor_7.dat 2019-05-15 09:30:10.001 AM 2019-05-18 11:30:10.000 AM
I have a requirement to remove the redundant timestamp ranges ie> the ones which fall under a given timestamp range. In this case for the file "monitor_5.dat" we need the mindatetime as 7AM and maxdatetime as 6PM as they form the logical min and max timestamp ranges which would cover the other entries.
So my resultant output should look like:
filename mindatetime maxdatetime
monitor_4.dat 2019-04-28 09:00:00 AM 2019-04-29 23:00:00 PM
monitor_5.dat 2019-04-28 07:00:00 AM 2019-04-28 06:00:00 PM
monitor_7.dat 2019-04-21 03:06:26.0 AM 2019-06-05 03:06:18.0 AM
monitor_7.dat 2019-05-12 07:00:10.001 AM 2019-05-13 10:00:10.000 AM
monitor_7.dat 2019-05-15 09:30:10.001 AM 2019-05-18 11:30:10.000 AM
This needs to be achieved through SQL only. Any suggestions would be helpful. I have already explored the "tsrange" function provided in Postgres but that is not helping me completely.