AnalystPath

Class Attendance for Every Member and Class

SQLEasyJunior level~15 min

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.

Members
member_idmember_name
1Maya
2Dev
6Otto
Classes
class_name
Spin
Yoga
Boxing
Attendance
member_idclass_name
1Spin
1Yoga
1Boxing

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

Related SQL questions