Find Employees With Over a Year of Tenure and No Review in the Last Six Months
Company: Lattice
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Using 2024-06-01 as today's date, return the `employee_id` and `name` of every employee who has been at the company for more than one year and has had no performance review within the last 6 months.
### Input Table(s)
`employees`
| Column | Type | Meaning |
| --- | --- | --- |
| employee_id | INT | Employee id. Primary key. |
| name | VARCHAR(100) | Employee name. NOT NULL. |
| hire_date | DATE | Date the employee joined. NOT NULL. |
`performance_reviews`
| Column | Type | Meaning |
| --- | --- | --- |
| review_id | INT | Review id. Primary key. |
| employee_id | INT | Employee who was reviewed. Foreign key to `employees(employee_id)`. |
| review_date | DATE | Date of the review. NOT NULL. |
### Output Contract
- Columns, in this order: `employee_id`, `name`.
- One row per qualifying employee, with no duplicates.
- Sort by `employee_id` ascending.
### Example
`employees`
| employee_id | name | hire_date |
| --- | --- | --- |
| 1 | Ana | 2020-03-15 |
| 2 | Ben | 2023-06-01 |
| 3 | Chen | 2022-01-10 |
| 4 | Dara | 2021-09-30 |
| 5 | Eli | 2024-02-01 |
| 6 | Fay | 2019-07-07 |
`performance_reviews`
| review_id | employee_id | review_date |
| --- | --- | --- |
| 101 | 3 | 2023-12-01 |
| 102 | 4 | 2023-11-30 |
| 103 | 4 | 2022-11-15 |
| 104 | 6 | 2023-05-05 |
| 105 | 6 | 2024-05-20 |
Expected result:
| employee_id | name |
| --- | --- |
| 1 | Ana |
| 4 | Dara |
Ana has more than a year of tenure and no reviews at all. Dara's latest review (2023-11-30) is one day before the 6-month window opens. Ben has exactly one year of tenure, which is not more than one year. Chen's review on 2023-12-01 falls inside the window, Eli was hired too recently, and Fay was reviewed on 2024-05-20.
### Constraints and Clarifications
- More than one year of tenure means `hire_date` is strictly before 2023-06-01. An employee hired on 2023-06-01 does not qualify.
- A review is within the last 6 months when `review_date` is on or after 2023-12-01. A review on 2023-12-01 counts as recent; one on 2023-11-30 does not.
- An employee with no reviews at all meets the review condition.
- An employee can have many reviews. One recent review is enough to exclude them, whatever their older reviews look like.
- There are 1 to 10,000 employees and 0 to 100,000 reviews.
- All dates are valid and none is after 2024-06-01.
- Use the fixed date 2024-06-01, not the current date.
```hint Employees without reviews
Make sure an employee with zero rows in `performance_reviews` still qualifies, and that one recent review excludes an employee even when they also have older ones.
```
Overview: Write a SQL query that finds employees with more than one year of tenure who have had no performance review in the last six months, measured from a fixed date. It tests date interval arithmetic, inclusive and exclusive boundaries, and filtering on the absence of related rows.
Using 2024-06-01 as today's date, return the employee_id and name of every employee who has been at the company for more than one year and has had no performance review within the last 6 months.
Table employees has one row per employee: employee_id (INTEGER, primary key), name (VARCHAR(100), NOT NULL) and hire_date (DATE, NOT NULL, the date the employee joined).
Table performance_reviews has one row per review: review_id (INTEGER, primary key), employee_id (INTEGER, the employee who was reviewed, a foreign key to employees.employee_id) and review_date (DATE, NOT NULL, the date of the review).
More than one year of tenure means hire_date is strictly before 2023-06-01. An employee hired on 2023-06-01 does not qualify.
A review is within the last 6 months when review_date is on or after 2023-12-01. A review on 2023-12-01 counts as recent; one on 2023-11-30 does not.
An employee with no reviews at all meets the review condition.
An employee can have many reviews. One recent review is enough to exclude them, whatever their older reviews look like.
There are 1 to 10,000 employees and 0 to 100,000 reviews. All dates are valid and none is after 2024-06-01.
Compute both conditions from the fixed date 2024-06-01; do not use the current date.
Return the columns employee_id and name, in that order, with one row per qualifying employee and no duplicates, sorted by employee_id ascending.
Tables
employees(employee_id INTEGER, name VARCHAR(100), hire_date DATE)
performance_reviews(review_id INTEGER, employee_id INTEGER, review_date DATE)
Hints
- Make sure an employee with zero rows in performance_reviews still qualifies, and that one recent review excludes an employee even when they also have older ones.
- Both date tests are fixed comparisons: hire_date must be strictly before 2023-06-01, and a review counts as recent when review_date is on or after 2023-12-01.