The Employees With Deductions interview question involves calculating the total work time for each employee based on logs and identifying those who worked fewer hours than required. You are typically given a table of employees with their required work hours and a Logs table with in_time and out_time. The catch is that each work session's duration is often rounded up to the nearest minute or hour, depending on the specific rules of the problem.
Amazon and other large enterprises use this database interview pattern to test data aggregation and time-based arithmetic. It evaluates whether a candidate can handle timestamp calculations, rounding logic (using CEIL or ROUND), and complex grouping. It’s a practical scenario reflecting payroll or attendance tracking systems.
The problem uses Timestamp Aggregation and Conditional Filtering.
TIMESTAMPDIFF(SECOND, in_time, out_time).CEIL() if the rule says "round up every session."SUM the durations per employee using GROUP BY.Employee table to compare the total worked time with the needed_hours.total_time < needed_hours.Employee 1 needs 10 hours. Logs:
Familiarize yourself with SQL time functions like TIMESTAMPDIFF, DATE_ADD, and EXTRACT. Different databases (MySQL, PostgreSQL, Oracle) have different syntax for these, so specify which one you are using.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Customer Purchasing Behavior Analysis | Medium | Solve | |
| Find Interview Candidates | Medium | Solve | |
| Find the Missing IDs | Medium | Solve | |
| Grand Slam Titles | Medium | Solve | |
| Number of Times a Driver Was a Passenger | Medium | Solve |