Class Attendance for Every Member and Class
Problem
Table: `Members`
```text
+-------------+---------+
| Column | Type |
+-------------+---------+
| member_id | int |
| member_name | varchar |
+-------------+---------+
member_id is the primary key.
```
Table: `Classes`
```text
+-------------+---------+
| Column | Type |
+-------------+---------+
| class_name | varchar |
+-------------+---------+
class_name is the primary key.
```
Table: `Attendance`
```text
+-------------+---------+
| Column | Type |
+-------------+---------+
| member_id | int |
| class_name | varchar |
+-------------+---------+
There is no primary key; rows may repeat. Each row is one time a member showed
up to a class. Every member is enrolled in every class.
```
Report, for every member and every class, how many times that member attended that class.
Return `member_id`, `member_name`, `class_name`, `times_attended`, ordered by `member_id` then `class_name`.
Tables
Example rows — the live problem includes the full dataset.
| member_id | member_name |
|---|---|
| 1 | Maya |
| 2 | Dev |
| 6 | Otto |
| class_name |
|---|
| Spin |
| Yoga |
| Boxing |
| member_id | class_name |
|---|---|
| 1 | Spin |
| 1 | Yoga |
| 1 | Boxing |
Expected output
Your answer should return 12 rows with the columns member_id, member_name, class_name, times_attended.
Starter code (SQL)
SELECT *
FROM Members;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock