Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Retention Rate SQL

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

Your question is Retention Rate SQL. Start with the requirements and the two 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

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results