Class Performance - Problem
Class Performance Analysis
You're a teacher who wants to understand the performance gap in your class. Given a table of student scores across three assignments, you need to calculate the difference between the highest and lowest total scores.
Input: A
•
•
•
•
•
Goal: Calculate each student's total score (sum of all 3 assignments), find the maximum and minimum totals, then return their difference.
Example:
If the highest total is 285 and the lowest is 180, return
You're a teacher who wants to understand the performance gap in your class. Given a table of student scores across three assignments, you need to calculate the difference between the highest and lowest total scores.
Input: A
Scores table with columns:•
student_id (int) - unique student identifier•
student_name (varchar) - student's name•
assignment1 (int) - score for first assignment•
assignment2 (int) - score for second assignment•
assignment3 (int) - score for third assignmentGoal: Calculate each student's total score (sum of all 3 assignments), find the maximum and minimum totals, then return their difference.
Example:
If the highest total is 285 and the lowest is 180, return
105. Input & Output
example_1.sql — Basic Example
$
Input:
Scores table:
| student_id | student_name | assignment1 | assignment2 | assignment3 |
|------------|--------------|-------------|-------------|-------------|
| 1 | Alice | 85 | 92 | 78 |
| 2 | Bob | 76 | 88 | 94 |
| 3 | Carol | 95 | 85 | 90 |
›
Output:
| score_difference |
|------------------|
| 15 |
💡 Note:
Alice's total: 85+92+78=255, Bob's total: 76+88+94=258, Carol's total: 95+85+90=270. Maximum is 270, minimum is 255, difference is 270-255=15.
example_2.sql — Same Scores
$
Input:
Scores table:
| student_id | student_name | assignment1 | assignment2 | assignment3 |
|------------|--------------|-------------|-------------|-------------|
| 1 | John | 80 | 80 | 80 |
| 2 | Jane | 90 | 70 | 80 |
| 3 | Jack | 75 | 85 | 80 |
›
Output:
| score_difference |
|------------------|
| 0 |
💡 Note:
All students have the same total score of 240 (80+80+80=240, 90+70+80=240, 75+85+80=240). Since max and min are equal, the difference is 0.
example_3.sql — Single Student
$
Input:
Scores table:
| student_id | student_name | assignment1 | assignment2 | assignment3 |
|------------|--------------|-------------|-------------|-------------|
| 1 | Solo | 100 | 95 | 98 |
›
Output:
| score_difference |
|------------------|
| 0 |
💡 Note:
With only one student, the maximum and minimum total scores are the same (293), so the difference is 0.
Constraints
- 1 ≤ number of students ≤ 1000
- 0 ≤ assignment scores ≤ 100
- All assignment scores are non-negative integers
- Each student has exactly 3 assignment scores
Visualization
Tap to expand
Understanding the Visualization
1
Calculate Each Total
Sum up all three assignment scores for each student
2
Track Extremes
Keep track of the highest and lowest total scores as we go
3
Find the Gap
Subtract the minimum from maximum to get the performance gap
4
Understand the Range
This difference shows how spread out the class performance is
Key Takeaway
🎯 Key Insight: Use SQL's aggregate functions MAX() and MIN() directly on calculated totals to find the performance gap in a single, efficient query.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code