Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compare Campaign Performance Across Months

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

Your question is Compare Campaign Performance Across Months. Start with the requirements and the two 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

BrightAds wants to compare campaign performance between two monthly time periods. Write a PostgreSQL query to calculate campaign metrics for January 2024 and February 2024, then show the change between the two periods.

Requirements

  1. Return one row per campaign that had at least one send in either January 2024 or February 2024.
  2. For each campaign, calculate:
    • jan_sends, jan_conversions, jan_conversion_rate
    • feb_sends, feb_conversions, feb_conversion_rate
  3. Compute conversion_rate_change as feb_conversion_rate - jan_conversion_rate.
  4. Include only campaigns where total sends across the two months are at least 2.
  5. Order results by conversion_rate_change descending, then campaign_name ascending.

Use campaigns for campaign metadata and campaign_events for send/conversion activity. A conversion is an event where event_type = 'conversion'. Ignore rows where event_date is NULL.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTUnique campaign identifier
campaign_nameVARCHAR(100)Campaign display name
channelVARCHAR(50)Marketing channel used for the campaign
start_dateDATECampaign launch date
campaign_events
ColumnTypeDescription
event_idPKINTUnique event identifier
campaign_idINTCampaign tied to the event
event_dateDATEDate the event occurred
event_typeVARCHAR(20)Type of event such as send or conversion
user_idINTUser associated with the event
Tablescampaignscampaign_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results