Employees Project Allocation - Problem
Employee Project Workload Analysis
You're tasked with analyzing employee project allocations to identify overworked team members. Given two database tables containing project assignments and employee information, you need to find employees whose project workload exceeds their team's average workload.
The
šÆ Find employees allocated to projects where their workload > average workload of their team
Return results ordered by
Tables Structure:
You're tasked with analyzing employee project allocations to identify overworked team members. Given two database tables containing project assignments and employee information, you need to find employees whose project workload exceeds their team's average workload.
The
Project table contains project assignments with workload values, while the Employees table contains employee details including their team assignments. Your goal is to:šÆ Find employees allocated to projects where their workload > average workload of their team
Return results ordered by
employee_id and project_id in ascending order.Tables Structure:
Project: project_id, employee_id, workloadEmployees: employee_id, name, team Input & Output
example_1.sql ā Basic Case
$
Input:
Project table:
| project_id | employee_id | workload |
|------------|-------------|----------|
| 1 | 1 | 80 |
| 2 | 2 | 60 |
| 3 | 3 | 90 |
| 4 | 1 | 70 |
Employees table:
| employee_id | name | team |
|-------------|-------|--------|
| 1 | Alice | Team A |
| 2 | Bob | Team A |
| 3 | Carol | Team B |
āŗ
Output:
| employee_id | project_id | name | team | workload |
|-------------|------------|-------|--------|-----------|
| 1 | 1 | Alice | Team A | 80 |
| 1 | 4 | Alice | Team A | 70 |
| 3 | 3 | Carol | Team B | 90 |
š” Note:
Team A average: (80+60+70)/3 = 70. Alice's workloads (80, 70) both exceed 70. Team B average: 90/1 = 90. Carol's workload (90) equals the average, so not included. Wait - Carol is the only one in Team B, so she can't exceed her own average.
example_2.sql ā Multiple Teams
$
Input:
Project table:
| project_id | employee_id | workload |
|------------|-------------|----------|
| 1 | 1 | 45 |
| 2 | 2 | 85 |
| 3 | 3 | 70 |
| 4 | 4 | 95 |
| 5 | 5 | 60 |
Employees table:
| employee_id | name | team |
|-------------|-------|--------|
| 1 | Alice | Dev |
| 2 | Bob | Dev |
| 3 | Carol | QA |
| 4 | David | QA |
| 5 | Eve | Dev |
āŗ
Output:
| employee_id | project_id | name | team | workload |
|-------------|------------|-------|------|-----------|
| 2 | 2 | Bob | Dev | 85 |
| 4 | 4 | David | QA | 95 |
š” Note:
Dev team average: (45+85+60)/3 = 63.33. Only Bob (85) exceeds this. QA team average: (70+95)/2 = 82.5. Only David (95) exceeds this.
example_3.sql ā Edge Case - Single Member Team
$
Input:
Project table:
| project_id | employee_id | workload |
|------------|-------------|----------|
| 1 | 1 | 80 |
| 2 | 2 | 90 |
Employees table:
| employee_id | name | team |
|-------------|-------|--------|
| 1 | Alice | Solo |
| 2 | Bob | Solo |
āŗ
Output:
| employee_id | project_id | name | team | workload |
|-------------|------------|------|------|-----------|
| 2 | 2 | Bob | Solo | 90 |
š” Note:
Both employees are in the same 'Solo' team. Team average: (80+90)/2 = 85. Only Bob's workload (90) exceeds the team average of 85.
Constraints
š”
Explanation
AI Ready
š” Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code