Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Monthly Campaign Spend Ranking

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Top Monthly Campaign Spend Ranking. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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

Problem

You are given campaign delivery data from StackAdapt and need to identify the top five ad campaigns by total spend for each month in the past year. Write a SQL query that returns one row per campaign-month, ranks campaigns within each month by spend, and keeps only the top five campaigns for each month.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTPrimary key for the campaign
campaign_nameVARCHAR(100)Campaign name in StackAdapt
advertiser_idINTAdvertiser that owns the campaign
statusVARCHAR(20)Campaign status
advertisers
ColumnTypeDescription
advertiser_idPKINTPrimary key for the advertiser
advertiser_nameVARCHAR(100)Advertiser name
spend_logs
ColumnTypeDescription
spend_idPKINTPrimary key for each spend record
campaign_idINTCampaign tied to the spend record
spend_dateDATEDate of spend
spend_amountDECIMAL(12,2)Spend amount for that day
Tablescampaignsadvertisersspend_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results