Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL on Advertiser Metrics

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

Your question is SQL on Advertiser Metrics. 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

Reddit Ads needs a weekly revenue report for advertiser performance. Assume the report is run for the week beginning 2025-02-17, so “last week” is 2025-02-10 through 2025-02-16, inclusive.

Write one PostgreSQL query that returns the daily performance of the advertiser with the highest total revenue last week. Include every day in the week, including days with no revenue for that advertiser. Also include the percentage of all advertisers whose total revenue last week exceeded $40. Advertisers with no revenue during the week must remain in the denominator.

Requirements

  1. Aggregate weekly revenue per advertiser, treating missing or NULL revenue as zero.
  2. Select one top advertiser using ROW_NUMBER(), breaking ties by advertiser_id.
  3. Return the top advertiser's daily revenue, weekly revenue, and the percentage of all advertisers above $40.
  4. Order results chronologically from Monday through Sunday.

Schema

advertisers
ColumnTypeDescription
advertiser_idPKINTUnique advertiser identifier
advertiser_nameVARCHAR(100)Advertiser display name
ad_revenue
ColumnTypeDescription
revenue_idPKINTUnique revenue record identifier
advertiser_idINTAdvertiser associated with the revenue
revenue_dateDATEDate on which revenue was recorded
revenueNUMERIC(10,2)Revenue amount in US dollars
Tablesadvertisersad_revenue
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results