Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.