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
Top Funnel Clicks and CPC
00:00
5 left

Top Funnel Clicks and CPC

MediumSQL · PostgreSQL

Problem

Meta's marketing analytics team wants a campaign-level view of top-of-funnel performance across recent ad delivery. Write a SQL query to return top-of-funnel clicks and cost per click (CPC) by campaign for the last 30 days.

Requirements

  1. Use only events from the last 30 days relative to DATE '2024-06-30'.
  2. Count only clicks where funnel_stage = 'top_of_funnel'.
  3. Sum spend from delivery records in the same 30-day window.
  4. Return one row per campaign with:
    • campaign_id
    • campaign_name
    • top_funnel_clicks
    • total_spend
    • cpc
  5. Include campaigns with spend but no top-of-funnel clicks; in that case, return 0 clicks and NULL CPC.
  6. Order results by top_funnel_clicks descending, then campaign_id ascending.

Schema

meta_campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Campaign name in Meta Ads Manager
objectiveVARCHAR(50)Campaign objective
statusVARCHAR(20)Current campaign status
meta_ad_delivery
ColumnTypeDescription
delivery_idPKINTUnique delivery record
campaign_idINTCampaign tied to spend
delivery_dateDATEDate of ad delivery
spend_usdDECIMAL(10,2)Spend recorded for that date
impressionsINTDelivered impressions
meta_click_events
ColumnTypeDescription
click_idPKINTUnique click event
campaign_idINTCampaign tied to the click
click_dateDATEDate of click
funnel_stageVARCHAR(30)Funnel stage classification
click_sourceVARCHAR(30)Source surface for the click
Tablesmeta_campaignsmeta_ad_deliverymeta_click_events
Interviewer

Your question is Top Funnel Clicks and CPC. 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.