Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
Start free
SQL for MoM Retention
00:00
5 left

SQL for MoM Retention

HardSQL · PostgreSQL

Problem

Thumbtack’s Marketing Analytics team wants to measure how consistently service professionals who joined the platform in 2024 remain active. Write a PostgreSQL query that calculates month-over-month retention by join-month cohort.

Requirements

  1. Include only service professionals whose joined_at date falls in 2024.
  2. Treat a professional as active in a month when at least one activity record exists during that month.
  3. For each cohort and activity month after the join month, return the previous-month active count, retained-professional count, and retention rate. Define retention as retained professionals divided by professionals active in the previous month.
  4. Deduplicate multiple activity records for the same professional in the same month and order results by cohort month and activity month.

Output details

  • Return columns cohort_month, activity_month, previous_month_active, retained_professionals, and retention_rate, in that order.
  • Sort by cohort_month ascending, then activity_month ascending.
  • Express retention_rate as a percentage multiplied by 100 and rounded to 2 decimal places.
  • Return NULL for retention_rate when previous_month_active is 0.
  • Return only cohort and activity-month pairs having at least one activity record after the cohort month.

Schema

service_professionals
ColumnTypeDescription
professional_idPKINTUnique service professional identifier
professional_nameVARCHAR(100)Professional display name
joined_atDATEDate the professional joined Thumbtack
cityVARCHAR(80)Primary service city
specialtyVARCHAR(100)Primary service category
professional_activity
ColumnTypeDescription
activity_idPKINTUnique activity record identifier
professional_idINTReferences service_professionals.professional_id
activity_atDATEDate of activity on Thumbtack
activity_typeVARCHAR(40)Type of professional activity
Tablesservice_professionalsprofessional_activity
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.