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
SQL for Publisher and Segment Performance
00:00
5 left

SQL for Publisher and Segment Performance

HardSQL · PostgreSQL

Problem

Write a SQL query to analyze Taboola campaign operations performance by publisher and advertiser segment, including joins across tables, monthly aggregation, and a ranking of the worst-performing segments.

Use the provided campaign and daily metrics data for January and February 2025. Rank segments within each publisher and month by return on spend, with the weakest performance ranked first.

Output

  1. One row per publisher, advertiser segment, and month.
  2. Columns: month, publisher_name, segment_name, impressions, clicks, conversions, spend, revenue, return_on_spend, and worst_rank.
  3. Include only campaigns with matching publishers, segments, and metrics in the period. Sort by month, publisher, rank, and segment name.

Schema

publishers
ColumnTypeDescription
publisher_idPKINTUnique publisher identifier
publisher_nameVARCHAR(100)Publisher display name
regionVARCHAR(50)Publisher operating region
advertiser_segments
ColumnTypeDescription
segment_idPKINTUnique advertiser segment identifier
segment_nameVARCHAR(100)Advertiser segment name
segment_typeVARCHAR(50)Segment classification
campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
publisher_idINTPublisher running the campaign
segment_idINTAdvertiser segment targeted by the campaign
campaign_nameVARCHAR(120)Campaign display name
statusVARCHAR(20)Campaign lifecycle status
campaign_metrics
ColumnTypeDescription
metric_idPKINTUnique daily metric identifier
campaign_idINTCampaign associated with the metrics
metric_dateDATEDate of the recorded metrics
impressionsINTNumber of served impressions
clicksINTNumber of ad clicks
conversionsINTNumber of conversions
spendNUMERIC(12,2)Campaign spend
revenueNUMERIC(12,2)Attributed campaign revenue
Tablespublishersadvertiser_segmentscampaignscampaign_metrics
Interviewer

Your question is SQL for Publisher and Segment Performance. 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.