AnalystPath

Members Who Outscore Their Team Leader

SQLEasyJunior level~15 min

Problem

Table: `TeamMember`

```text
+-----------+---------+
| Column | Type |
+-----------+---------+
| member_id | int |
| full_name | varchar |
| points | int |
| leader_id | int |
+-----------+---------+
member_id is the primary key. leader_id points to the member_id of this
person's team leader, or is NULL for a member who has no leader.
```

Write a query that returns the name of every member whose `points` are strictly greater than the `points` of their own team leader. Use the column heading `Member`.

Return the rows in any order.

**Example**

```text
TeamMember:
+-----------+-----------+--------+-----------+
| member_id | full_name | points | leader_id |
+-----------+-----------+--------+-----------+
| 1 | Dana | 70 | 3 |
| 2 | Omer | 80 | 4 |
| 3 | Rina | 60 | NULL |
| 4 | Gil | 90 | NULL |
+-----------+-----------+--------+-----------+

Output:
+--------+
| Member |
+--------+
| Dana |
+--------+
```

Dana has 70 points and her leader Rina has 60, so Dana qualifies. Omer has 80 but his leader Gil has 90, so he does not. Rina and Gil have no leader, so they cannot qualify.

Tables

Example rows — the live problem includes the full dataset.

TeamMember
member_idfull_namepointsleader_id
1Dana703
2Omer804
3Rina60

Expected output

Your answer should return 1 row with the columns Member.

Starter code (SQL)

SELECT *
FROM TeamMember;

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