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 Marketing Channels with Window Functions
00:00
5 left

Top Marketing Channels with Window Functions

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify the top-performing marketing channels using window functions.

Use the provided campaign, spend, conversion, and channel data. Evaluate performance monthly using return on ad spend, and include month-over-month ROAS change.

Output

  1. One row per channel-month among the three highest-ranked channels in each month.
  2. Columns: month, channel_name, roas, channel_rank, previous_month_roas, and roas_change.
  3. Sort by month ascending, channel_rank ascending, and channel_name ascending.

Schema

channels
ColumnTypeDescription
channel_idPKINTUnique marketing channel identifier
channel_nameVARCHAR(100)Marketing channel name
campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
channel_idINTAssociated marketing channel
campaign_nameVARCHAR(150)Campaign name
ad_spend
ColumnTypeDescription
spend_idPKINTUnique spend record identifier
campaign_idINTCampaign receiving the spend
spend_dateDATEDate of the spend
spend_amountNUMERIC(12,2)Amount spent
conversions
ColumnTypeDescription
conversion_idPKINTUnique conversion identifier
campaign_idINTCampaign attributed to the conversion
conversion_dateDATEDate of the conversion
conversion_valueNUMERIC(12,2)Revenue attributed to the conversion
Tableschannelscampaignsad_spendconversions
Interviewer

Your question is Top Marketing Channels with Window Functions. Start with the requirements and the four 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.