AnalystPath

Loyalty Tier of Each Subscriber

SQLMediumMid level~15 min

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.

subscribers
subscriber_idhandle
1ava
2ben
3cy
sessions
session_idsubscriber_id
101
111
122
orders
order_idsession_id
10010
10111
10212

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

Related SQL questions