Compute 48 Hour Opt-Out Rate for Each SMS Campaign

Last updated: November 29, 2026

Quick Overview

Given a table of campaign sends and a table of subscriber opt-outs, compute for each campaign the number of unique recipients, how many opted out within 48 hours after receiving it, and the opt-out rate.

Attentive
Data Manipulation (SQL/Python)
Data Scientist
Attentive
November 29, 2026
Data Scientist
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a table of campaign sends and a table of subscriber opt-outs, compute for each campaign the number of unique recipients, how many opted out within 48 hours after receiving it, and the opt-out rate.

Opt-out rate is a health metric that Attentive's customer success and data teams watch for every campaign, because aggressive sends burn a brand's subscriber list. This screen checks careful joins with a time window and deduplication, not advanced SQL.

What the Interviewer Expects
  • Deduplicate repeat sends to the same subscriber within a campaign
  • Use a half-open time window starting at the send time
  • Count a subscriber once even if they have several opt-out rows
  • Avoid inflating counts with a plain join that fans out
  • Express the rate as a percentage with safe division
Key Topics to Cover
Time-window joins
EXISTS
Deduplication
Rates and ratios
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • A subscriber got two campaigns an hour apart and then opted out. Which campaign gets the blame?
  • How would you compare opt-out rates fairly between brands with very different list sizes?
  • How would you flag campaigns whose opt-out rate is unusually high for that brand?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

campaign_sends(campaign_id, subscriber_id, sent_at) can contain more than one row per subscriber per campaign, for example retries or an MMS fallback. `opt_outs(subscriber_id, opted_out_at, keyword)...

Approach
  1. Collapse sends to one row per (campaign, subscriber) with the earliest sent_at.
  2. For each recipient, flag whether any opt-out falls in the window. Use EXISTS rather than a join so that multip...

Submit Your Answer
Markdown supported

Related Questions