Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Churn Products by Region

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Churn Products by Region. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Deutsche Telekom wants to compare subscription churn across regional product portfolios, including MagentaMobil, MagentaTV, and broadband products. Write a PostgreSQL query to identify the top three products by churn rate within each region for subscriptions started during the first half of 2025.

Requirements

  1. Join regions, products, and subscriptions using their key relationships.
  2. Calculate each product's churn rate as churned eligible subscriptions divided by eligible subscriptions, expressed as a percentage. A subscription is churned when churned_at is not null.
  3. Include products with no eligible subscriptions, treating their churn rate as 0.00 percent.
  4. Rank products within each region by churn rate descending, then product ID ascending, and return only the top three products per region.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique regional market identifier
region_nameVARCHAR(100)Name of the regional market
products
ColumnTypeDescription
product_idPKINTUnique product identifier
region_idINTReferences the product's regional market
product_nameVARCHAR(150)Deutsche Telekom product name
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription identifier
product_idINTReferences the subscribed product
start_dateDATEDate on which the subscription started
churned_atDATEDate the subscription churned, or NULL if retained
Tablesregionsproductssubscriptions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results