Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Retention Over Six Months

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

Your question is SQL Retention Over Six Months. 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

Thumbtack wants to measure whether service professionals who completed a job during January 2025 continued completing jobs over the following five months. Write a PostgreSQL query that calculates monthly retention for this January cohort.

Requirements

  1. Define the cohort as distinct professionals with a completed job from January 1 through January 31, 2025.
  2. Return one row for each month from January through June 2025, including the cohort month.
  3. Calculate retained professionals, the fixed cohort size, and retention rate as a percentage. Count a professional once per month, even if they completed multiple jobs.
  4. Include months with no activity and order the output chronologically.

Schema

professionals
ColumnTypeDescription
professional_idPKINTUnique Thumbtack service professional identifier
service_categoryVARCHAR(50)Primary service category listed by the professional
onboarded_atDATEDate the professional joined Thumbtack
jobs
ColumnTypeDescription
job_idPKINTUnique job identifier
professional_idINTProfessional assigned to the job
statusVARCHAR(20)Current job status
completed_atTIMESTAMPTimestamp when the job was completed
Tablesprofessionalsjobs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results