Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Cohort Payment Trends SQL

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

Your question is Cohort Payment Trends 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

Rover's Business Analytics team wants to monitor payment performance across user cohorts. Write a PostgreSQL query that summarizes the last four calendar quarters represented by payment activity for selected Rover cohorts.

Requirements

  1. Join users to payments and include only the New Sitter, Experienced Sitter, and New Pet Parent cohorts.
  2. Return one row per cohort and quarter, including payment attempts, successful payments, successful gross amount, Rover fees, net amount, and success rate.
  3. Treat only payments with status = 'succeeded' as successful financial activity. Use 0 for financial totals when no payment in a group qualifies.
  4. Order results by cohort and quarter chronologically. Derive the four-quarter range from the latest payment date in the selected cohorts.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Rover user identifier
cohort_labelVARCHAR(40)Business-defined user cohort
signup_dateDATEDate the user joined Rover
payments
ColumnTypeDescription
payment_idPKINTUnique payment attempt identifier
user_idINTUser associated with the payment attempt
payment_dateDATEDate of the payment attempt
statusVARCHAR(20)Payment processing status
amountNUMERIC(10,2)Payment amount before Rover fees
rover_feeNUMERIC(10,2)Fee retained by Rover
payment_methodVARCHAR(20)Payment method used
Tablesuserspayments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results