Flatten/merge overlapping time intervals
问题 I have a 'Service' table with millions of rows. Each row corresponds to a service provided by a staff in a given date and time interval (Each row has a unique ID). There are cases where a staff might provide services in overlapping time frames. I need to write a query that merges overlapping time intervals and returns the data in the format shown below. I tried grouping by StaffID and Date fields and getting the Min of BeginTime and Max of EndTime but that does not account for the non