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
Flag Missing Marketing Spend Days
00:00
5 left

Flag Missing Marketing Spend Days

MediumSQL · PostgreSQL

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
Interviewer

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