Knowledge Guide
HomeDatabasesSQL Practice Problems

easy Employee Performance and Improvement Rate

Problem Statement

Table: Performance
Each row in this table represents a performance evaluation of an employee, detailing the employee's name, the evaluation result, the evaluation round, and the performance score.

+----------------+---------+
| Column Name    | Type    |          
+----------------+---------+
| employee_name  | varchar |           
| evaluation     | varchar |       
| round          | int     |          
| score          | int     |    
+----------------+---------+
This table may have duplicate rows.
This table contains information collected from performance evaluations of employees.
The round column has a value from 1 to 10.
The score column has a value from 1 to 100. An evaluation with a score less than 50 is considered a poor evaluation.

Develop a solution to find each employee_name, their performance, and improvement_rate.

We define employee performance as:

We also define improvement rate as:

Both performance and improvement_rate should be rounded to 2 decimal places.

Return the result table in any order.

Example

Input:

Performance table: +---------------+-------------+-------+-------+ | employee_name | evaluation | round | score | +---------------+-------------+-------+-------+ | Alice | Efficiency | 1 | 80 | | Alice | Productivity| 2 | 90 | | Alice | Creativity | 3 | 60 | | Bob | Efficiency | 1 | 40 | | Bob | Productivity| 2 | 60 | | Bob | Creativity | 3 | 70 | +---------------+-------------+-------+-------+

Output:

+---------------+-----------+-------------------+ | employee_name | performance | improvement_rate | +---------------+-----------+-------------------+ | Alice | 48.33 | 33.33 | | Bob | 31.11 | 66.67 | +---------------+-----------+-------------------+

Output Explanation

Step 1: Calculate Employee Performance

For each employee:

  1. Divide the score by the round for all evaluations.
  2. Calculate the average of these ratios.

Step 2: Calculate Improvement Rate

For each employee:

  1. Check if the score in each round:

    • Is greater than 50.
    • Is greater than the score in the previous round.
  2. Count the number of evaluations that meet the criteria.

Try It Yourself

java
-- TODO: Write your user queries here

Solution

To solve this problem, we need to calculate each employee's performance and improvement rate based on their evaluation scores across different rounds. The approach involves systematically breaking down the problem into manageable steps, utilizing SQL window functions and aggregation techniques to derive the required metrics.

SQL Query

WITH LaggedPerformance AS ( SELECT employee_name, round, score, LAG(score) OVER (PARTITION BY employee_name ORDER BY round) AS previous_score FROM Performance ) SELECT employee_name, ROUND(AVG(score * 1.0 / round), 2) AS performance, ROUND( (SUM(CASE WHEN score > 50 AND previous_score IS NOT NULL AND score > previous_score THEN 1 ELSE 0 END) * 100.0 / COUNT(*)), 2 ) AS improvement_rate FROM LaggedPerformance GROUP BY employee_name;

Step-by-Step Approach

Step 1: Calculate Performance

Compute the average of the ratio between each employee's score and the evaluation round to assess overall performance.

SQL Query:

SELECT employee_name, AVG(score * 1.0 / round) AS performance FROM Performance GROUP BY employee_name;

Explanation:

Output After Step 1:

+---------------+-------------+ | employee_name | performance | +---------------+-------------+ | Alice | 48.3333333 | | Bob | 31.111111 | +---------------+-------------+

Step 2: Determine Improvement Rate

Calculate the percentage of evaluations where an employee's score improved compared to the previous round and is greater than 50.

SQL Query:

WITH LaggedPerformance AS ( SELECT employee_name, round, score, LAG(score) OVER (PARTITION BY employee_name ORDER BY round) AS previous_score FROM Performance ) SELECT employee_name, ROUND( (SUM(CASE WHEN score > 50 AND previous_score IS NOT NULL AND score > previous_score THEN 1 ELSE 0 END) * 100.0 / COUNT(*)), 2 ) AS improvement_rate FROM LaggedPerformance GROUP BY employee_name;

Explanation:

Output After Step 2:

+---------------+-------------------+ | employee_name | improvement_rate | +---------------+-------------------+ | Alice | 33.33 | | Bob | 66.67 | +---------------+-------------------+

Step 3: Combine Performance and Improvement Rate

Objective:
Merge the performance and improvement rate calculations to present a consolidated view for each employee.

SQL Query:

WITH LaggedPerformance AS ( SELECT employee_name, round, score, LAG(score) OVER (PARTITION BY employee_name ORDER BY round) AS previous_score FROM Performance ) SELECT employee_name, ROUND(AVG(score * 1.0 / round), 2) AS performance, ROUND( (SUM(CASE WHEN score > 50 AND previous_score IS NOT NULL AND score > previous_score THEN 1 ELSE 0 END) * 100.0 / COUNT(*)), 2 ) AS improvement_rate FROM LaggedPerformance GROUP BY employee_name;

Explanation:

Final Output:

+---------------+-------------+-------------------+ | employee_name | performance | improvement_rate | +---------------+-------------+-------------------+ | Alice | 48.33 | 33.33 | | Bob | 31.11 | 66.67 | +---------------+-------------+-------------------+
🤖 Don't fully get this? Learn it with Claude

Stuck on Employee Performance and Improvement Rate? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🪜 Hint ladder (no spoilers)

Progressively stronger hints — you still solve it.

I'm working on the problem **Employee Performance and Improvement Rate** (Databases). Give me a HINT LADDER: start with the tiniest nudge, then wait. Only reveal the next, stronger hint when I ask. Do NOT show the full solution unless I type 'show solution'. Keep me doing the thinking. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🎨 Explain the approach visually

See the technique, not just code.

Explain the optimal approach to **Employee Performance and Improvement Rate** with a VISUAL walkthrough: trace it on a small concrete example using ASCII art / a step-by-step diagram, narrate what changes each step, then give time & space complexity with a one-line derivation. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🔍 Review my solution

Catch bugs, edge cases, sub-optimality.

I'll paste my solution to **Employee Performance and Improvement Rate**. Review it for correctness, missed edge cases, and time/space complexity, then coach me toward the optimal — don't just rewrite it. Ask me to paste my code now. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🔁 Drill the pattern

Lock in recognition with look-alikes.

Give me 2 problems that use the SAME underlying pattern as **Employee Performance and Improvement Rate**. For each, let me attempt first, then review my answer and name the trigger signal that reveals the pattern. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes