Find Students Whose Total Marks Across Courses Exceed 870
Quick Overview
Write a SQL query that returns the students whose total marks across all their courses are strictly above 870. It tests joining child rows to a parent table, grouping by the right key, and filtering on an aggregate at the exact boundary.
Find Students Whose Total Marks Across Courses Exceed 870
Company: Texas Instruments
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Return the `name` of every student whose total `marks` across all courses is strictly greater than 870. Exclude students with no courses or a total of 870 or below.
```hint What the threshold is compared against
Check whether 870 is tested against a single course row or against a student's total, and where in the query each of those can be filtered.
```
### Input Table(s)
Table `Student`:
| Column | Type | Meaning |
|---|---|---|
| `id` | INT | Student identifier |
| `name` | VARCHAR(100) | Student name, not null |
Key: `id` is the primary key.
Table `Course`:
| Column | Type | Meaning |
|---|---|---|
| `id` | INT | Course row identifier |
| `marks` | INT | Marks the student earned in this course, not null |
| `s_id` | INT | Student who took the course |
Keys: `id` is the primary key. `s_id` is a foreign key to `Student(id)`.
### Output Contract
- One column: `name`.
- One row per qualifying student. Two different students who share a name each get their own row.
- Sorted by `Student.id` ascending. The id is not returned, but it is unique, so the order is fully determined.
- Marks are integers, so no rounding applies.
### Example
`Student`:
| id | name |
|---|---|
| 1 | Dan |
| 2 | Eve |
`Course`:
| id | marks | s_id |
|---|---|---|
| 1 | 870 | 1 |
| 2 | 500 | 2 |
| 3 | 400 | 2 |
Expected result:
| name |
|---|
| Eve |
Dan's total is exactly 870, which is not strictly greater than 870 and is excluded. Eve's total is 900 and qualifies.
### Constraints and Clarifications
- There are between 1 and 10,000 students, and each student has between 0 and 100 courses.
- `marks` is between 0 and 1000.
- `Student.id` and `Course.id` are unique, and every `Course.s_id` matches an existing `Student.id`.
- No NULLs reach the calculation: `marks` is `NOT NULL` and every course belongs to a student.
- A student with no rows in `Course` has no total and is excluded. A total of exactly 870 is also excluded.
- Every course row counts toward the total, including two courses with the same marks.
Overview: Write a SQL query that returns the students whose total marks across all their courses are strictly above 870. It tests joining child rows to a parent table, grouping by the right key, and filtering on an aggregate at the exact boundary.
Return the name of every student whose total marks across all courses is strictly greater than 870. Exclude students with no courses or a total of 870 or below.
Input Table(s)
Table Student:
Column
Type
Meaning
id
INT
Student identifier
name
VARCHAR(100)
Student name, not null
Key: id is the primary key.
Table Course:
Column
Type
Meaning
id
INT
Course row identifier
marks
INT
Marks the student earned in this course, not null
s_id
INT
Student who took the course
Keys: id is the primary key. s_id is a foreign key to Student(id).
Output Contract
One column:
name
.
One row per qualifying student. Two different students who share a name each get their own row.
Sorted by
Student.id
ascending. The id is not returned, but it is unique, so the order is fully determined.
Marks are integers, so no rounding applies.
Example
Student:
id
name
1
Dan
2
Eve
Course:
id
marks
s_id
1
870
1
2
500
2
3
400
2
Expected result:
name
Eve
Dan's total is exactly 870, which is not strictly greater than 870 and is excluded. Eve's total is 900 and qualifies.
Constraints and Clarifications
There are between 1 and 10,000 students, and each student has between 0 and 100 courses.
marks
is between 0 and 1000.
Student.id
and
Course.id
are unique, and every
Course.s_id
matches an existing
Student.id
.
No NULLs reach the calculation:
marks
is
NOT NULL
and every course belongs to a student.
A student with no rows in
Course
has no total and is excluded. A total of exactly 870 is also excluded.
Every course row counts toward the total, including two courses with the same marks.