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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
SQL Joins and Aggregations for Performance
00:00
5 left

SQL Joins and Aggregations for Performance

MediumSQL · PostgreSQL

Problem

Can you write a SQL query using joins, subqueries, and group by to analyze marketing database performance?

Use the provided marketing tables for the January 2025 reporting period. Include active campaigns whose dates overlap January 2025, including campaigns with no matching activity.

Output

  1. One row per qualifying campaign.
  2. Return campaign_id, campaign_name, channel, total_spend, impressions, clicks, conversions, revenue, ctr_percent, conversion_rate_percent, roas, channel_avg_spend, and roas_rank.
  3. Sort by channel, roas_rank, and campaign_id.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Campaign display name
channelVARCHAR(50)Marketing channel
start_dateDATECampaign start date
end_dateDATECampaign end date
budgetDECIMAL(12,2)Allocated campaign budget
statusVARCHAR(20)Campaign lifecycle status
campaign_metrics
ColumnTypeDescription
metric_idPKINTUnique metric record identifier
campaign_idINTReferenced campaign
metric_dateDATEDate of measured activity
impressionsINTAd impressions
clicksINTAd clicks
spendDECIMAL(12,2)Spend recorded for the metric date
attributed_conversions
ColumnTypeDescription
conversion_idPKINTUnique conversion record identifier
campaign_idINTCampaign credited with the conversions
conversion_dateDATEDate of attributed conversions
conversionsINTNumber of conversions
revenueDECIMAL(12,2)Revenue attributed to conversions
Tablescampaignscampaign_metricsattributed_conversions
Interviewer

Your question is SQL Joins and Aggregations for Performance. 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.