Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Retention Rate SQL With Joins

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

Your question is Retention Rate SQL With Joins. 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

Tiger Analytics is preparing a customer retention dashboard. Write a PostgreSQL query that calculates how many customers active in each month also returned during the immediately following calendar month.

Requirements

  1. Deduplicate customer activity to one row per customer per calendar month.
  2. For each month, return the prior month's active customer count, the count retained in the next month, and the retention rate as a percentage.
  3. Include months with no retained customers and order results chronologically.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer name
emailVARCHAR(150)Customer email address
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_dateDATEDate the order was placed
order_statusVARCHAR(20)Current order status
Tablescustomersorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results