Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.