Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Top Churn Products by Region
00:00
5 left

Top Churn Products by Region

MediumSQL · PostgreSQL

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.

Output details

  • Return columns in this order: region_name, product_name, churned_subscriptions, eligible_subscriptions, churn_rate_pct, rank_in_region.
  • Round churn_rate_pct to two decimal places.
  • Filter subscription start dates inclusively from 2025-01-01 through exclusively before 2025-07-01.
  • Order the final results by region_name ascending, then rank_in_region ascending.

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
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.