PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers

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.

Last updated: May 7, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.

Related Coding 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)