PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Data Manipulation (SQL/Python)/OpenAI

Handle repeated churn in SQL

Last updated: May 7, 2026

Quick Overview

This question evaluates proficiency in time-based data manipulation and analytics, including handling repeated churn and resubscription, interval logic, deduplication, and per-user metric derivation using SQL and Python.

  • hard
  • OpenAI
  • Data Manipulation (SQL/Python)
  • Data Scientist

Handle repeated churn in SQL

Company: OpenAI

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: hard

Interview Round: Technical Screen

As part of analyzing the same promotion experiment, you need SQL that handles users who churn and later resubscribe. Assume the following tables: 1. experiment_assignments - user_id BIGINT - variant STRING -- control or free_month - assigned_at TIMESTAMP This table already contains only users who qualified for the experiment, so you do not need to implement eligibility logic. 2. subscription_periods - user_id BIGINT - period_start_at TIMESTAMP - period_end_at TIMESTAMP NULL -- exclusive end time; NULL means the subscription is still active Each row represents one continuous subscription period. A user may appear in multiple rows if they churn and later resubscribe. Key relationship: experiment_assignments.user_id = subscription_periods.user_id. All timestamps are in UTC. For users assigned between 2025-01-01 00:00:00 UTC and 2025-01-31 23:59:59 UTC, write SQL that returns one row per assigned user with the following columns: - user_id - variant - converted_within_7d: 1 if the user starts any subscription in the interval [assigned_at, assigned_at + 7 days) - active_on_day_30: 1 if the user has an active subscription at exactly assigned_at + 30 days, even if they churned and resubscribed before day 30 - had_churn_and_return_before_day_30: 1 if the user has at least two distinct subscription periods with period_start_at < assigned_at + 30 days After producing the user-level result, explain how you would aggregate it to variant-level conversion and 30-day retention metrics.

Quick Answer: This question evaluates proficiency in time-based data manipulation and analytics, including handling repeated churn and resubscription, interval logic, deduplication, and per-user metric derivation using SQL and Python.

Related Interview Questions

  • Write SQL for repeat churn - OpenAI (hard)
  • Compute churn with re-subscriptions - OpenAI (hard)
  • Debug and harden trial-assignment Python code - OpenAI (Medium)
  • Write SQL for post-trial conversion cohorts - OpenAI (Medium)
  • Write SQL to compute signup and retention lift - OpenAI (medium)
|Home/Data Manipulation (SQL/Python)/OpenAI

Handle repeated churn in SQL

OpenAI logo
OpenAI
Jan 22, 2026, 12:00 AM
hardData ScientistTechnical ScreenData Manipulation (SQL/Python)
12
0
Practice Read
Loading...

As part of analyzing the same promotion experiment, you need SQL that handles users who churn and later resubscribe.

Assume the following tables:

  1. experiment_assignments
  • user_id BIGINT
  • variant STRING -- control or free_month
  • assigned_at TIMESTAMP This table already contains only users who qualified for the experiment, so you do not need to implement eligibility logic.
  1. subscription_periods
  • user_id BIGINT
  • period_start_at TIMESTAMP
  • period_end_at TIMESTAMP NULL -- exclusive end time; NULL means the subscription is still active Each row represents one continuous subscription period. A user may appear in multiple rows if they churn and later resubscribe.

Key relationship: experiment_assignments.user_id = subscription_periods.user_id. All timestamps are in UTC.

For users assigned between 2025-01-01 00:00:00 UTC and 2025-01-31 23:59:59 UTC, write SQL that returns one row per assigned user with the following columns:

  • user_id
  • variant
  • converted_within_7d: 1 if the user starts any subscription in the interval [assigned_at, assigned_at + 7 days)
  • active_on_day_30: 1 if the user has an active subscription at exactly assigned_at + 30 days, even if they churned and resubscribed before day 30
  • had_churn_and_return_before_day_30: 1 if the user has at least two distinct subscription periods with period_start_at < assigned_at + 30 days

After producing the user-level result, explain how you would aggregate it to variant-level conversion and 30-day retention metrics.

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More OpenAI•More Data Scientist•OpenAI Data Scientist•OpenAI Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.