You are given a table EmployeeShifts containing information about employee work shifts with start and end times.
Your task: Count the number of overlapping shifts for each employee. Two shifts are considered overlapping if one shift's end_time is later than another shift's start_time.
Return the result table ordered by employee_id in ascending order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
employee_id
PK
|
int | ID of the employee |
start_time
PK
|
time | Start time of the shift |
end_time
|
time | End time of the shift |
Input & Output
| employee_id | start_time | end_time |
|---|---|---|
| 1 | 09:00:00 | 12:00:00 |
| 1 | 11:00:00 | 14:00:00 |
| 2 | 10:00:00 | 13:00:00 |
| employee_id | overlapping_shifts |
|---|---|
| 1 | 1 |
Employee 1 has two shifts: 09:00-12:00 and 11:00-14:00. These shifts overlap because the first shift ends at 12:00, which is after the second shift starts at 11:00. Employee 2 has only one shift, so no overlaps are possible.
| employee_id | start_time | end_time |
|---|---|---|
| 3 | 08:00:00 | 11:00:00 |
| 3 | 09:00:00 | 12:00:00 |
| 3 | 10:00:00 | 13:00:00 |
| employee_id | overlapping_shifts |
|---|---|
| 3 | 2 |
Employee 3 has three shifts with multiple overlaps: shift 1 (08:00-11:00) overlaps with shift 2 (09:00-12:00), and shift 2 overlaps with shift 3 (10:00-13:00). This results in 2 overlapping pairs.
| employee_id | start_time | end_time |
|---|---|---|
| 4 | 08:00:00 | 10:00:00 |
| 4 | 11:00:00 | 13:00:00 |
| 4 | 14:00:00 | 16:00:00 |
| employee_id | overlapping_shifts |
|---|
Employee 4 has three shifts but none overlap - each shift ends before the next one starts. Since there are no overlapping shifts, this employee doesn't appear in the result.
Constraints
-
1 ≤ employee_id ≤ 1000 -
start_timeandend_timeare valid time values -
start_time < end_timefor all shifts