Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Scenarios for Marketing Tables
00:00
5 left

SQL Scenarios for Marketing Tables

MediumSQL · PostgreSQL

Problem

Canva’s marketing analytics team wants to identify the best-performing channel for each active campaign during Q1 2026. Write one PostgreSQL query using the campaign, channel, and daily performance tables.

Requirements

  1. Include only active campaigns launched on or before 2026-03-31, active marketing channels, and performance recorded from 2026-01-01 through 2026-03-31.
  2. Aggregate spend, impressions, clicks, and conversions by campaign and channel.
  3. Calculate click-through rate as clicks divided by impressions, expressed as a percentage, and cost per conversion.
  4. Rank channels within each campaign by conversions descending, then spend ascending, and return only the top-ranked channel for each campaign.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Canva marketing campaign name
campaign_statusVARCHAR(20)Campaign lifecycle status
launch_dateDATEDate the campaign launched
marketing_channels
ColumnTypeDescription
channel_idPKINTUnique marketing channel identifier
channel_nameVARCHAR(50)Marketing channel name
channel_typeVARCHAR(30)Channel category
channel_statusVARCHAR(20)Whether the channel is active
campaign_daily_performance
ColumnTypeDescription
performance_idPKINTUnique performance row identifier
campaign_idINTReferences campaigns.campaign_id
channel_idINTReferences marketing_channels.channel_id
performance_dateDATEDate of the performance measurement
spendDECIMAL(12,2)Daily media spend
impressionsINTDaily ad impressions
clicksINTDaily ad clicks
conversionsINTDaily attributed conversions
Tablescampaignsmarketing_channelscampaign_daily_performance
Interviewer

Your question is SQL Scenarios for Marketing Tables. 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.