Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rolling 30-Day CAC SQL
00:00
5 left

Rolling 30-Day CAC SQL

HardSQL · PostgreSQL

Problem

Write a SQL query to calculate the rolling 30-day customer acquisition cost (CAC) across different marketing channels for Wise.

Use the supplied marketing spend and customer acquisition records. Include channels and dates represented in either source, treat missing spend or acquisition activity as zero, and return NULL when the rolling acquisition count is zero.

Output

  1. One row per channel and activity date.
  2. Columns: channel, activity_date, rolling_spend, rolling_new_customers, and rolling_cac.
  3. Sort by channel ascending, with NULL channels first, then activity_date ascending.

Schema

marketing_spend
ColumnTypeDescription
spend_idPKINTUnique marketing spend record identifier
channelVARCHAR(50)Wise marketing channel associated with the spend
spend_dateDATEDate on which the spend was recorded
amountDECIMAL(12,2)Marketing spend amount in the reporting currency
customer_acquisitions
ColumnTypeDescription
acquisition_idPKINTUnique acquisition event identifier
channelVARCHAR(50)Wise marketing channel attributed to the acquisition
customer_idINTNewly acquired Wise customer identifier
acquisition_dateDATEDate on which the customer was acquired
Tablesmarketing_spendcustomer_acquisitions
Interviewer

Your question is Rolling 30-Day CAC SQL. Start with the requirements and the two 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.