Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Joins for Campaign and Transactions

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Joins for Campaign and Transactions. Start with the requirements and the three tables on the right.

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.

Problem

Write a SQL query utilizing different types of JOINs to combine Seatgeek marketing campaign spend data with user transaction records.

Use the provided tables and return one row per campaign with spend. Include campaigns with no matching completed transactions, exclude spend rows whose campaign ID is not defined, and count only completed transactions.

Output

  1. Columns: campaign_id, campaign_name, total_spend, completed_transactions, completed_revenue
  2. One row per defined campaign with at least one spend record
  3. Order by campaign_id ascending

Schema

marketing_campaigns
ColumnTypeDescription
campaign_idPKVARCHAR(20)Unique Seatgeek marketing campaign identifier
campaign_nameVARCHAR(100)Campaign display name
channelVARCHAR(30)Primary marketing channel
campaign_spend
ColumnTypeDescription
spend_idPKINTUnique spend record identifier
campaign_idVARCHAR(20)Campaign associated with the spend record
spend_dateDATEDate the spend was recorded
spend_amountNUMERIC(12,2)Marketing spend amount
user_transactions
ColumnTypeDescription
transaction_idPKINTUnique user transaction identifier
user_idINTUser associated with the transaction
campaign_idVARCHAR(20)Campaign attributed to the transaction
transaction_dateDATEDate of the transaction
statusVARCHAR(20)Transaction lifecycle status
gross_amountNUMERIC(12,2)Gross transaction amount
Tablesmarketing_campaignscampaign_spenduser_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results