AnalystPath

Verified References on Each Order

SQLMediumMid level~15 min

Problem

Table: `Member`

```text
+-------------+---------+
| Column | Type |
+-------------+---------+
| member_id | int |
| member_name | varchar |
| email | varchar |
+-------------+---------+
member_id is the primary key. A platform member with a registered email.
```

Table: `Reference`

```text
+-------------+---------+
| Column | Type |
+-------------+---------+
| member_id | int |
| ref_name | varchar |
| ref_email | varchar |
+-------------+---------+
Each row is a reference contact a member listed. A reference is **verified**
when its ref_email matches the email of some registered member.
```

Table: `Order`

```text
+-----------+---------+
| Column | Type |
+-----------+---------+
| order_id | int |
| total | int |
| member_id | int |
+-----------+---------+
order_id is the primary key. An order placed by a member.
```

For each order report: `order_id`, the ordering member's `member_name`, the order `total`, the number of references that member listed (`refs_cnt`), and how many of those references are verified (`verified_cnt`). Order the result by `order_id`.

**Example**

```text
If a member listed 3 references and 2 of their ref_emails belong to
registered members, that order shows refs_cnt = 3 and verified_cnt = 2.
```

Tables

Example rows — the live problem includes the full dataset.

Member
member_idmember_nameemail
1Noanoa@mail.io
2Raviravi@mail.io
3Solsol@mail.io
Reference
member_idref_nameref_email
1r1ravi@mail.io
1r2ghost@mail.io
2r3sol@mail.io
Order
order_idtotalmember_id
102001
111502

Expected output

Your answer should return 2 rows with the columns order_id, member_name, total, refs_cnt, verified_cnt.

Starter code (SQL)

SELECT *
FROM Member;

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