Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Top Digital Services Per Region
00:00
5 left

Top Digital Services Per Region

MediumSQL · PostgreSQL

Problem

Apple wants to compare the monthly performance of digital services such as Apple Music, Apple TV+, and iCloud+ across customer regions. Write a PostgreSQL query that aggregates service revenue by month and identifies the highest-performing services within each region and month.

Requirements

  1. Join service_usage to digital_services and aggregate revenue by region, month, and service.
  2. Use DENSE_RANK to rank services by monthly revenue within each region and month, preserving ties.
  3. Use ROW_NUMBER to provide a deterministic position within each region and month, ordering tied services by service name.
  4. Return services in the top two dense-rank levels, ordered by region, month, and row number. Treat missing revenue as zero.

Schema

digital_services
ColumnTypeDescription
service_idPKINTUnique Apple digital service identifier
service_nameVARCHAR(100)Apple digital service name
service_categoryVARCHAR(50)Category of the digital service
service_usage
ColumnTypeDescription
usage_idPKINTUnique usage record identifier
service_idINTReferences digital_services.service_id
regionVARCHAR(50)Customer geographic region
usage_dateDATEDate associated with usage revenue
revenueNUMERIC(12,2)Revenue attributed to the service usage
Tablesdigital_servicesservice_usage
Interviewer

Your question is Top Digital Services Per Region. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.