Kindly help me writing a query for below problem.
I WANT Min start date time and max end date time of overlapping date ranges and same start & end date time for not overlapped date ranges in SQL Server
Example:- My_table
NAME | Start Date Time | End DAte time |
---|---|---|
Aman | 01-02-2020 04:30 | 01-02-2020 06:30 |
Aman | 01-02-2020 08:30 | 01-02-2020 09:30 |
Aman | 01-02-2020 04:40 | 01-02-2020 05:30 |
Aman | 01-02-2020 04:55 | 01-02-2020 07:30 |
Aman | 01-02-2020 14:55 | 01-02-2020 18:30 |
Aman | 01-02-2020 13:40 | 01-02-2020 15:30 |
Ram | 01-02-2020 04:40 | 01-02-2020 05:30 |
Ram | 01-02-2020 04:40 | 01-02-2020 05:30 |
Expected result will be only overlapped date and time:
(minimum and maximum time between all overlapped)
NAME | Start Date Time | End Date time |
---|---|---|
Aman | 01-02-2020 04:30 | 01-02-2020 07:30 |
Aman | 01-02-2020 08:30 | 01-02-2020 09:30 |
Aman | 01-02-2020 13:40 | 01-02-2020 18:30 |
Ram | 01-02-2020 04:40 | 01-02-2020 05:30 |
First row of Result Values has overlapped date ranges so we right min and max of that all overlapped date ranges of that Name.
Second row has no any overlap so we write it as it is ..
Third row is overlapping so we write min and max of overlapped dates of Aman.
Fourth row is also overlapping so we right it once with min and max date range.
Kindly help me in this asap, I already wasted 5 days in searching solution of this ...