Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Pivot Lucid Campaign Performance by Month

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Pivot Lucid Campaign Performance by Month. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

You are given campaign delivery and conversion data from Lucid Motors marketing efforts. Write a PostgreSQL query that returns one row per campaign for January 2024, showing the campaign name, channel, total spend, total leads, total test-drive bookings, and separate monthly session totals for the Lucid website and the Lucid app. Only include campaigns whose January spend is greater than 0 and whose total January leads are at least 20.

This tests the same thinking behind nested IF statements, INDEX-MATCH lookups, and pivot tables in Excel, but in SQL: conditional logic with CASE, joining lookup data, and reshaping metrics into columns.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Campaign name
channelVARCHAR(50)Marketing acquisition channel
regionVARCHAR(50)Campaign target region
campaign_daily_metrics
ColumnTypeDescription
metric_idPKINTUnique daily metric row identifier
campaign_idINTCampaign identifier linked to campaigns
metric_dateDATEDate of the metric
surfaceVARCHAR(50)Lucid touchpoint surface such as Website or App
spend_usdNUMERIC(10,2)Daily media spend in USD
sessionsINTDaily sessions or visits
leadsINTDaily lead count
test_drive_bookingsINTDaily test-drive bookings
channel_targets
ColumnTypeDescription
channelPKVARCHAR(50)Marketing channel
target_cplNUMERIC(10,2)Target cost per lead for the channel
active_flagBOOLEANWhether the target is currently active
Tablescampaignscampaign_daily_metricschannel_targets
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results