You are given a table Scores that contains student information and their assignment scores.
Table: Scores
| Column Name | Type |
|---|---|
| student_id | int |
| student_name | varchar |
| assignment1 | int |
| assignment2 | int |
| assignment3 | int |
student_id is the column of unique values for this table.
Task: Write a SQL solution to calculate the difference between the highest total score and the lowest total score among all students. The total score for each student is the sum of all three assignments.
Return the result in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
student_id
PK
|
int | Unique identifier for each student |
student_name
|
varchar | Name of the student |
assignment1
|
int | Score for assignment 1 |
assignment2
|
int | Score for assignment 2 |
assignment3
|
int | Score for assignment 3 |
Input & Output
| student_id | student_name | assignment1 | assignment2 | assignment3 |
|---|---|---|---|---|
| 1 | Alice | 90 | 85 | 88 |
| 2 | Bob | 78 | 82 | 75 |
| 3 | Charlie | 95 | 92 | 97 |
| score_difference |
|---|
| 49 |
Alice's total: 90+85+88 = 263, Bob's total: 78+82+75 = 235, Charlie's total: 95+92+97 = 284. The difference between highest (284) and lowest (235) is 49.
| student_id | student_name | assignment1 | assignment2 | assignment3 |
|---|---|---|---|---|
| 1 | Alice | 80 | 80 | 80 |
| 2 | Bob | 80 | 80 | 80 |
| score_difference |
|---|
| 0 |
Both students have the same total score of 240, so the difference between highest and lowest is 0.
| student_id | student_name | assignment1 | assignment2 | assignment3 |
|---|---|---|---|---|
| 1 | Alice | 90 | 85 | 88 |
| score_difference |
|---|
| 0 |
With only one student, both the highest and lowest scores are the same (263), resulting in a difference of 0.
Constraints
-
1 ≤ student_id ≤ 1000 -
student_nameconsists of lowercase English letters -
0 ≤ assignment1, assignment2, assignment3 ≤ 100 - At least one student record exists in the table