Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Networks by Rolling ROAS

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

Your question is Top Networks by Rolling ROAS. Start with the requirements and the four 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results