Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Flag Missing Marketing Spend Days

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

Your question is Flag Missing Marketing Spend Days. Start with the requirements and the three 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

You are given a small marketing pipeline feeding an executive dashboard. Write a PostgreSQL query that returns one row per report_date and campaign_name for January 2024, showing the cleaned spend, clicks, and conversions used in reporting, plus a data quality status. Treat missing metric rows as 0, negative spend or clicks as anomalies that should be replaced with 0, and rows with NULL conversions as missing conversions that should also be reported as 0. Label each row as ok, missing_metrics, or anomalous_metrics.

Return only active Google Ads campaigns, keep dates even when no metric row exists, and sort by date then campaign name.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTPrimary key for the campaign
campaign_nameVARCHAR(100)Google marketing campaign name
channelVARCHAR(50)Acquisition channel such as Google Ads or DV360
is_activeBOOLEANWhether the campaign is currently active
daily_metrics
ColumnTypeDescription
metric_idPKINTPrimary key for the daily metric row
campaign_idINTCampaign identifier
report_dateDATEDate of the reported metrics
spend_usdNUMERIC(10,2)Daily ad spend in USD
clicksINTDaily clicks
conversionsINTDaily conversions
calendar
ColumnTypeDescription
calendar_datePKDATECalendar date used to generate expected reporting days
Tablescampaignsdaily_metricscalendar
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results