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
Retention Rate SQL
00:00
5 left

Retention Rate SQL

HardSQL · PostgreSQL

Problem

Wise Energy wants to measure whether customers return to the product after signing up. Write a PostgreSQL query that calculates 30-day retention by signup cohort, using activity recorded in the Wise Energy product.

A user is retained if they perform at least one qualifying activity during days 1 through 30 after signup, inclusive. Use 2024-04-30 as the reporting date, so include only users whose full 30-day observation period has elapsed.

Requirements

  1. Return one row per signup date.
  2. Include eligible users, retained users, and retention percentage.
  3. Count each user once, even if they have multiple qualifying events.
  4. Include cohorts with no qualifying activity, and order results chronologically.

Output details

  • Use cohort_date, eligible_users, retained_users, and retention_rate_pct in that order.
  • Treat energy_report_viewed, bill_estimate_created, and tariff_checked as qualifying activities.
  • Include users whose signup_date is on or before 2024-03-31.
  • Measure activity from signup plus one day, inclusive, through signup plus 31 days, exclusive.
  • Round retention_rate_pct to two decimal places.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Wise Energy user identifier
signup_dateDATEDate the user signed up
energy_events
ColumnTypeDescription
event_idPKINTUnique activity event identifier
user_idINTUser associated with the event
event_typeVARCHAR(50)Type of Wise Energy activity
occurred_atTIMESTAMPTimestamp when the activity occurred
Tablesusersenergy_events
Interviewer

Your question is Retention Rate SQL. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.