Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Seattle Sitters by Repeat Rate

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

Your question is Top Seattle Sitters by Repeat Rate. 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

Business Context

You’re working on analytics for a pet-sitting marketplace (think Rover-scale) with millions of bookings per year across major US cities. The Seattle operations team is rolling out a loyalty program and wants to identify the sitters who drive the most repeat business—because repeat bookings correlate strongly with higher lifetime value and lower customer acquisition costs.

In this marketplace, a repeat booking is defined as a pet owner booking the same sitter more than once (across different bookings). The team wants a leaderboard of the best-performing sitters in Seattle by repeat booking rate, with ties broken deterministically.

Task

Write a SQL query to find the top 10 sitters in Seattle based on repeat booking rate.

Requirements

  1. Consider only bookings where the sitter’s city = 'Seattle'.
  2. Consider only bookings with status = 'completed' (ignore cancelled/refunded).
  3. Define repeat booking rate per sitter as:
    • repeat_booking_rate = (number of completed bookings that are repeats) / (total completed bookings)
    • A booking is a repeat if it is not the first completed booking for that (owner_id, sitter_id) pair.
  4. Return these columns:
    • sitter_id, sitter_name, total_completed_bookings, repeat_completed_bookings, repeat_booking_rate
  5. Order results by:
    • repeat_booking_rate DESC,
    • then total_completed_bookings DESC,
    • then sitter_id ASC.
  6. Return only the top 10 rows.

Schema

sitters
ColumnTypeDescription
sitter_idPKINTUnique identifier for the sitter
sitter_nameVARCHAR(100)Sitter display name
cityVARCHAR(100)Primary city where the sitter operates
created_atTIMESTAMPTimestamp when the sitter joined
bookings
ColumnTypeDescription
booking_idPKBIGINTUnique identifier for the booking
owner_idBIGINTUnique identifier for the pet owner
sitter_idINTSitter who fulfilled the booking (FK to sitters)
start_dateDATEStart date of the booking
end_dateDATEEnd date of the booking
statusVARCHAR(20)Booking status (completed, cancelled, refunded, etc.)
booked_atTIMESTAMPTimestamp when the booking was created
Tablessittersbookings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results