Skip to content

Commit cbc0991

Browse files
committed
task: #3611
1 parent cde26cd commit cbc0991

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
192192
- [3580. Find Consistently Improving Employees](./leetcode/medium/3580.%20Find%20Consistently%20Improving%20Employees.sql)
193193
- [3586. Find COVID Recovery Patients](./leetcode/medium/3586.%20Find%20COVID%20Recovery%20Patients.sql)
194194
- [3601. Find Drivers with Improved Fuel Efficiency](./leetcode/medium/3601.%20Find%20Drivers%20with%20Improved%20Fuel%20Efficiency.sql)
195+
- [3611. Find Overbooked Employees](./leetcode/medium/3611.%20Find%20Overbooked%20Employees.sql)
195196
3. [Hard](./leetcode/hard/)
196197
- [185. Department Top Three Salaries](./leetcode/hard/185.%20Department%20Top%20Three%20Salaries.sql)
197198
- [262. Trips and Users](./leetcode/hard/262.%20Trips%20and%20Users.sql)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Question 3611. Find Overbooked Employees
3+
Link: https://leetcode.com/problems/find-overbooked-employees/description/?envType=problem-list-v2&envId=database
4+
5+
Table: employees
6+
7+
+---------------+---------+
8+
| Column Name | Type |
9+
+---------------+---------+
10+
| employee_id | int |
11+
| employee_name | varchar |
12+
| department | varchar |
13+
+---------------+---------+
14+
employee_id is the unique identifier for this table.
15+
Each row contains information about an employee and their department.
16+
Table: meetings
17+
18+
+---------------+---------+
19+
| Column Name | Type |
20+
+---------------+---------+
21+
| meeting_id | int |
22+
| employee_id | int |
23+
| meeting_date | date |
24+
| meeting_type | varchar |
25+
| duration_hours| decimal |
26+
+---------------+---------+
27+
meeting_id is the unique identifier for this table.
28+
Each row represents a meeting attended by an employee. meeting_type can be 'Team', 'Client', or 'Training'.
29+
Write a solution to find employees who are meeting-heavy - employees who spend more than 50% of their working time in meetings during any given week.
30+
31+
Assume a standard work week is 40 hours
32+
Calculate total meeting hours per employee per week (Monday to Sunday)
33+
An employee is meeting-heavy if their weekly meeting hours > 20 hours (50% of 40 hours)
34+
Count how many weeks each employee was meeting-heavy
35+
Only include employees who were meeting-heavy for at least 2 weeks
36+
Return the result table ordered by the number of meeting-heavy weeks in descending order, then by employee name in ascending order.
37+
*/
38+
39+
WITH weeks_stats AS (
40+
SELECT
41+
employee_id,
42+
EXTRACT(WEEK FROM meeting_date) AS week, --noqa: RF04
43+
SUM(duration_hours) AS meet
44+
FROM meetings
45+
GROUP BY employee_id, week
46+
HAVING SUM(duration_hours) > 20
47+
)
48+
49+
SELECT
50+
e.employee_id,
51+
e.employee_name,
52+
e.department,
53+
COUNT(e.employee_id) AS meeting_heavy_weeks
54+
FROM weeks_stats AS ws
55+
LEFT JOIN
56+
employees AS e
57+
ON ws.employee_id = e.employee_id
58+
GROUP BY e.employee_id, e.employee_name, e.department
59+
HAVING COUNT(e.employee_id) >= 2
60+
ORDER BY meeting_heavy_weeks DESC, e.employee_name ASC

0 commit comments

Comments
 (0)