Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Channel Metrics
00:00
5 left

SQL for Channel Metrics

MediumSQL · PostgreSQL

Problem

Write a SQL query to combine campaign performance data from multiple tables and calculate key marketing metrics by channel.

Use all campaign rows, including channels with no activity. Count approved conversions and handle missing values and zero denominators appropriately.

Output

  1. One row per channel with channel, impressions, clicks, spend, conversions, attributed_revenue, ctr_percent, conversion_rate_percent, cost_per_click, and roas.
  2. Include zero totals where no activity exists and NULL for undefined rate metrics.
  3. Order by channel ascending.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(150)Campaign name
channelVARCHAR(50)Marketing channel
campaign_performance
ColumnTypeDescription
campaign_idPKINTCampaign receiving the performance activity
performance_datePKDATEDate of the performance record
impressionsINTNumber of ad impressions
clicksINTNumber of ad clicks
spendDECIMAL(12,2)Campaign spend
campaign_conversions
ColumnTypeDescription
conversion_idPKINTUnique conversion identifier
campaign_idINTCampaign attributed to the conversion
conversion_statusVARCHAR(20)Conversion review status
attributed_revenueDECIMAL(12,2)Revenue attributed to the conversion
Tablescampaignscampaign_performancecampaign_conversions
Interviewer

Your question is SQL for Channel Metrics. 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.