Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Users Exposed to Multiple Campaigns

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

Your question is Users Exposed to Multiple Campaigns. Start with the requirements and the three 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

Netflix marketing analytics needs to identify members who saw multiple active campaigns during the same calendar week. Write a PostgreSQL query that deduplicates repeated exposures to the same campaign before counting campaigns.

Requirements

  1. Consider weeks beginning on Monday using PostgreSQL DATE_TRUNC('week', exposed_at).
  2. Include only exposures with a non-null timestamp and campaigns whose status is active.
  3. Count each distinct campaign once per user and week, even if the user had repeated exposure events.
  4. Return the user ID, email, week start date, number of distinct campaigns, and a comma-separated alphabetical list of campaign names.
  5. Return only user-week combinations with at least two distinct campaigns, ordered by user ID and week.

Schema

users
ColumnTypeDescription
user_idPKINTNetflix member identifier
emailVARCHAR(255)Member email address
campaign_exposures
ColumnTypeDescription
exposure_idPKINTExposure event identifier
user_idINTReferenced member
campaign_idINTReferenced campaign
exposed_atTIMESTAMPTimestamp when the campaign was shown
channelVARCHAR(50)Netflix marketing surface or channel
campaigns
ColumnTypeDescription
campaign_idPKINTCampaign identifier
campaign_nameVARCHAR(150)Campaign name
statusVARCHAR(20)Campaign lifecycle status
Tablesuserscampaign_exposurescampaigns
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results