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
Compare Campaign Performance Periods
00:00
5 left

Compare Campaign Performance Periods

MediumSQL · PostgreSQL

Problem

Rippling's growth team launched a campaign in Rippling Spend on 2024-02-15 and wants a quick before-vs-after performance read. Write a SQL query to compare daily campaign performance for the periods before and after launch.

Requirements

  1. Use only the campaign_events table.
  2. Return one row per period: Before Launch and After Launch.
  3. For each period, calculate:
    • total_impressions
    • total_clicks
    • total_signups
    • ctr = total_clicks / total_impressions
    • signup_rate = total_signups / total_clicks
  4. Include only rows where event_date is between 2024-02-08 and 2024-02-21 inclusive.
  5. Treat dates before 2024-02-15 as Before Launch, and dates on or after 2024-02-15 as After Launch.
  6. Order the output by period so After Launch appears first.

Output details

  • Round ctr and signup_rate to 4 decimal places.
  • Return NULL when the denominator for ctr or signup_rate is zero.

Schema

campaign_events
ColumnTypeDescription
event_idPKINTPrimary key for each daily campaign record
event_dateDATEDate of campaign activity
campaign_nameVARCHAR(100)Campaign name in Rippling Spend
impressionsINTNumber of impressions recorded that day
clicksINTNumber of clicks recorded that day
signupsINTNumber of signups attributed that day
channelVARCHAR(50)Marketing channel
Tablescampaign_events
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the one table are in the Question tab.

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.