Loyalty Tier of Each Subscriber
Problem
Table: `subscribers`
| Column Name | Type |
|---|---|
| subscriber_id | int |
| handle | varchar |
`subscriber_id` is the primary key.
Table: `sessions`
| Column Name | Type |
|---|---|
| session_id | int |
| subscriber_id | int |
`session_id` is the primary key. Each row is one app session opened by a subscriber.
Table: `orders`
| Column Name | Type |
|---|---|
| order_id | int |
| session_id | int |
`order_id` is the primary key. Each row is a purchase made during a session.
For each subscriber, compute their conversion rate as `100 * (number of sessions that led to an order) / (number of sessions)`, then assign a tier: `Platinum` when the rate is at least `80`, `Silver` when it is in `[50, 80)`, `Bronze` when it is below `50`, and `Inactive` when the subscriber had no sessions at all. Return `subscriber_id`, `handle`, and the assigned `tier`. Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
| subscriber_id | handle |
|---|---|
| 1 | ava |
| 2 | ben |
| 3 | cy |
| session_id | subscriber_id |
|---|---|
| 10 | 1 |
| 11 | 1 |
| 12 | 2 |
| order_id | session_id |
|---|---|
| 100 | 10 |
| 101 | 11 |
| 102 | 12 |
Expected output
Your answer should return 4 rows with the columns subscriber_id, handle, tier.
Starter code (SQL)
SELECT *
FROM subscribers;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