From a4f7f101837902217ad4ff209ca6b52194222e29 Mon Sep 17 00:00:00 2001 From: ivanbyone Date: Tue, 29 Jul 2025 00:33:36 +0300 Subject: [PATCH] task: #3611 --- README.md | 1 + .../3611. Find Overbooked Employees.sql | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 leetcode/medium/3611. Find Overbooked Employees.sql diff --git a/README.md b/README.md index b1ad918..53b748b 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,7 @@ Useful for preparing for technical interviews and improving your SQL skills. - [3580. Find Consistently Improving Employees](./leetcode/medium/3580.%20Find%20Consistently%20Improving%20Employees.sql) - [3586. Find COVID Recovery Patients](./leetcode/medium/3586.%20Find%20COVID%20Recovery%20Patients.sql) - [3601. Find Drivers with Improved Fuel Efficiency](./leetcode/medium/3601.%20Find%20Drivers%20with%20Improved%20Fuel%20Efficiency.sql) + - [3611. Find Overbooked Employees](./leetcode/medium/3611.%20Find%20Overbooked%20Employees.sql) 3. [Hard](./leetcode/hard/) - [185. Department Top Three Salaries](./leetcode/hard/185.%20Department%20Top%20Three%20Salaries.sql) - [262. Trips and Users](./leetcode/hard/262.%20Trips%20and%20Users.sql) diff --git a/leetcode/medium/3611. Find Overbooked Employees.sql b/leetcode/medium/3611. Find Overbooked Employees.sql new file mode 100644 index 0000000..e4c239d --- /dev/null +++ b/leetcode/medium/3611. Find Overbooked Employees.sql @@ -0,0 +1,60 @@ +/* +Question 3611. Find Overbooked Employees +Link: https://leetcode.com/problems/find-overbooked-employees/description/?envType=problem-list-v2&envId=database + +Table: employees + ++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| employee_id | int | +| employee_name | varchar | +| department | varchar | ++---------------+---------+ +employee_id is the unique identifier for this table. +Each row contains information about an employee and their department. +Table: meetings + ++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| meeting_id | int | +| employee_id | int | +| meeting_date | date | +| meeting_type | varchar | +| duration_hours| decimal | ++---------------+---------+ +meeting_id is the unique identifier for this table. +Each row represents a meeting attended by an employee. meeting_type can be 'Team', 'Client', or 'Training'. +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. + +Assume a standard work week is 40 hours +Calculate total meeting hours per employee per week (Monday to Sunday) +An employee is meeting-heavy if their weekly meeting hours > 20 hours (50% of 40 hours) +Count how many weeks each employee was meeting-heavy +Only include employees who were meeting-heavy for at least 2 weeks +Return the result table ordered by the number of meeting-heavy weeks in descending order, then by employee name in ascending order. +*/ + +WITH weeks_stats AS ( + SELECT + employee_id, + EXTRACT(WEEK FROM meeting_date) AS week, --noqa: RF04 + SUM(duration_hours) AS meet + FROM meetings + GROUP BY employee_id, week + HAVING SUM(duration_hours) > 20 +) + +SELECT + e.employee_id, + e.employee_name, + e.department, + COUNT(e.employee_id) AS meeting_heavy_weeks +FROM weeks_stats AS ws +LEFT JOIN + employees AS e + ON ws.employee_id = e.employee_id +GROUP BY e.employee_id, e.employee_name, e.department +HAVING COUNT(e.employee_id) >= 2 +ORDER BY meeting_heavy_weeks DESC, e.employee_name ASC