Find Consistently Improving Employees - Problem

You are given two tables: employees and performance_reviews. Find employees who have consistently improved their performance over their last three reviews.

Requirements:

  • An employee must have at least 3 reviews to be considered
  • The employee's last 3 reviews must show strictly increasing ratings (each review better than the previous)
  • Use the most recent 3 reviews based on review_date for each employee
  • Calculate the improvement score as the difference between the latest rating and the earliest rating among the last 3 reviews

Return the result table ordered by improvement score in descending order, then by name in ascending order.

Table Schema

employees
Column Name Type Description
employee_id PK int Unique identifier for each employee
name varchar Employee's full name
Primary Key: employee_id
performance_reviews
Column Name Type Description
review_id PK int Unique identifier for each review
employee_id int Foreign key referencing employees table
review_date date Date when the performance review was conducted
rating int Performance rating on scale of 1-5 (5 is excellent, 1 is poor)
Primary Key: review_id

Input & Output

Example 1 — Consistently Improving Employee
Input Tables:
employees
employee_id name
1 John Smith
2 Alice Johnson
3 Bob Wilson
performance_reviews
review_id employee_id review_date rating
1 1 2024-01-15 3
2 1 2024-02-15 4
3 1 2024-03-15 5
4 2 2024-01-10 2
5 2 2024-02-10 2
6 2 2024-03-10 3
7 3 2024-01-20 4
8 3 2024-02-20 3
Output:
name improvement_score
John Smith 2
💡 Note:

John Smith has 3 reviews with ratings 3→4→5, showing consistent improvement. Alice Johnson's ratings are 2→2→3 (not strictly increasing since 2=2). Bob Wilson only has 2 reviews, not meeting the minimum requirement of 3 reviews.

Example 2 — Multiple Improving Employees
Input Tables:
employees
employee_id name
1 Sarah Davis
2 Mike Brown
performance_reviews
review_id employee_id review_date rating
1 1 2024-01-01 2
2 1 2024-02-01 3
3 1 2024-03-01 5
4 1 2024-04-01 4
5 2 2024-01-05 1
6 2 2024-02-05 2
7 2 2024-03-05 3
Output:
name improvement_score
Mike Brown 2
Sarah Davis 1
💡 Note:

Sarah Davis has 4 reviews, but only the last 3 are considered: 3→5→4. Since 5>4 is false, she doesn't qualify for consistent improvement based on most recent 3. Wait, let me recalculate: last 3 reviews by date are 5→4 (decreasing), so she doesn't qualify. Mike Brown has ratings 1→2→3, showing consistent improvement with score 2. Only Mike qualifies.

Example 3 — No Qualifying Employees
Input Tables:
employees
employee_id name
1 Tom Wilson
performance_reviews
review_id employee_id review_date rating
1 1 2024-01-01 4
2 1 2024-02-01 3
3 1 2024-03-01 5
Output:
name improvement_score
💡 Note:

Tom Wilson has ratings 4→3→5 over time. Since 3<4, this is not consistently improving (there's a decrease from 4 to 3), so no employees qualify for the result.

Constraints

  • 1 ≤ employee_id ≤ 1000
  • 1 ≤ rating ≤ 5
  • review_date is a valid date
  • Each employee can have multiple performance reviews

Visualization

Tap to expand
Find Consistently Improving EmployeesEmployeesemployee_idname1John SmithPerformance Reviewsemp_idreview_dateratingtrend12024-01-153oldest12024-02-1543>4 ✓12024-03-1554>5 ✓WindowFunctionResult: Improving Employeesnameimprovement_scoreJohn Smith2Improvement Score = Latest (5) - Earliest (3) = 2Only employees with strictly increasing last 3 ratings qualify
Understanding the Visualization
1
Input Tables
Employees and their performance reviews with ratings
2
Window Functions
Rank reviews and compare consecutive ratings
3
Filter & Calculate
Find improving employees and compute improvement score
Key Takeaway
🎯 Key Insight: Use window functions to efficiently check rating progression patterns across time-ordered reviews
Asked in
Amazon 12 Microsoft 8 Google 6
23.4K Views
Medium Frequency
~18 min Avg. Time
856 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen