Returning Early Users 2

Start Timer

0:00:00

Upvote
0
Downvote
Save question
Mark as completed
View comments

CloudSphere, a SaaS analytics platform, wants to understand customer expansion behavior across regions. The business team is particularly interested in identifying accounts that not only upgraded their subscription but also showed strong engagement after upgrading.

Given the table account_subscription_activity, write a SQL query to return, for each region, the top 3 upgraded accounts ranked by:

  1. Highest post_upgrade_active_days

  2. If there is a tie, earlier upgrade_date should rank higher

Only consider accounts that meet all of the following criteria:

  • Their subscription status changed from “STANDARD” to either “PREMIUM” or “ENTERPRISE”
  • post_upgrade_active_days ≥ 20
  • upgrade_date falls within the last 90 days, relative to the maximum upgrade date in the dataset

Return the final result ordered by:

  1. region
  2. post_upgrade_active_days DESC
  3. upgrade_date ASC

Schema

Input

account_subscription_activity

Column Type
account_id VARCHAR
region VARCHAR
previous_tier VARCHAR
new_tier VARCHAR
upgrade_date DATE
post_upgrade_active_days INTEGER

Output

Column Type
region VARCHAR
account_id VARCHAR
new_tier VARCHAR
upgrade_date DATE
post_upgrade_active_days INTEGER

Example

Input Data

account_id region previous_tier new_tier upgrade_date post_upgrade_active_days
A1 APAC STANDARD PREMIUM 2025-06-01 42
A2 APAC STANDARD ENTERPRISE 2025-06-10 55
A3 APAC STANDARD PREMIUM 2025-07-15 25
A4 EU STANDARD PREMIUM 2025-05-20 30
A5 EU STANDARD STANDARD 2025-06-05 28
A6 EU STANDARD ENTERPRISE 2025-07-10 48

Assume the maximum upgrade_date in the dataset is 2025-07-15, so the last 90-day window applies relative to that date.

Output

region account_id new_tier upgrade_date post_upgrade_active_days
APAC A2 ENTERPRISE 2025-06-10 55
APAC A1 PREMIUM 2025-06-01 42
APAC A3 PREMIUM 2025-07-15 25
EU A6 ENTERPRISE 2025-07-10 48
EU A4 PREMIUM 2025-05-20 30

Explanation:

Only accounts upgrading from STANDARD to PREMIUM/ENTERPRISE and active at least 20 days post-upgrade are considered. The dataset is restricted to upgrades within the most recent 90-day window. Within each region, the top 3 accounts are selected, ranked by highest post-upgrade activity and then earliest upgrade date.

.
.
.
.
.


Comments

Loading comments