Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Campaigns Per Region With Dense Rank

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

Your question is Top Campaigns Per Region With Dense Rank. Start with the requirements and the two 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

EXL Service Philippines marketing analysts need to compare campaign performance across regional markets. Write a PostgreSQL query that identifies the highest-performing campaigns in each region based on total conversions.

Requirements

  1. Aggregate conversion totals for each campaign, including campaigns without performance records.
  2. Use DENSE_RANK() to rank campaigns separately within each region.
  3. Return every campaign with a rank of 3 or better. Because dense ranking preserves ties, a region may return more than three campaigns.
  4. Sort the output by region, performance rank, and campaign name.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Name of the marketing campaign
regionVARCHAR(50)Philippine region targeted by the campaign
campaign_performance
ColumnTypeDescription
performance_idPKINTUnique performance record identifier
campaign_idINTReferences campaigns.campaign_id
reporting_dateDATEDate covered by the performance record
conversionsINTNumber of attributed conversions
Tablescampaignscampaign_performance
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results