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 Networks by Rolling ROAS
00:00
5 left

Top Networks by Rolling ROAS

MediumSQL · PostgreSQL

Problem

Tatari needs a daily view of which advertising networks are producing the strongest return on ad spend. Using campaign-level spend and attributed revenue, write a PostgreSQL query that ranks the active networks for the 30-day period ending on 2025-03-31.

Requirements

  1. Include activity from 2025-03-02 through 2025-03-31, inclusive.
  2. Aggregate spend and attributed revenue across all campaigns belonging to each active network.
  3. Calculate ROAS as attributed revenue divided by spend, safely handling zero or missing values.
  4. Return the top three networks, ordered by ROAS descending, with network name, total spend, attributed revenue, ROAS, and rank.
  5. Exclude networks with no positive spend and revenue or spend recorded outside the rolling window.

Representative Data

Schema

networks
ColumnTypeDescription
network_idPKINTEGERUnique network identifier
network_nameVARCHAR(100)Tatari advertising network name
is_activeBOOLEANWhether the network is active
campaigns
ColumnTypeDescription
campaign_idPKINTEGERUnique campaign identifier
network_idINTEGEROwning network identifier
campaign_nameVARCHAR(150)Campaign name
spend_daily
ColumnTypeDescription
spend_idPKINTEGERUnique spend record identifier
campaign_idINTEGERCampaign associated with the spend
spend_dateDATEDate on which spend occurred
spend_amountNUMERIC(12,2)Amount spent
revenue_daily
ColumnTypeDescription
revenue_idPKINTEGERUnique revenue record identifier
campaign_idINTEGERCampaign receiving attribution
revenue_dateDATEDate of attributed revenue
attributed_revenueNUMERIC(12,2)Revenue attributed to the campaign
Tablesnetworkscampaignsspend_dailyrevenue_daily
Interviewer

Your question is Top Networks by Rolling ROAS. 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.