Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Tenants by Payment Timeliness

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

Your question is Rank Tenants by Payment Timeliness. Start with the requirements and the three 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

AppFolio Property Manager provides property teams with payment and lease activity data. Write a PostgreSQL query that ranks tenants by payment timeliness within each property.

A payment is considered completed only when payment_status = 'paid' and paid_date is not null. A completed payment is on time when its paid_date is on or before its due_date.

Requirements

  1. Calculate each tenant's completed payment count, on-time payment percentage, and average days late. Treat on-time payments as zero days late.
  2. Include only tenants with at least two completed payments.
  3. Rank tenants separately within each property by on-time percentage descending, then average days late ascending. Use the tenant ID as a deterministic final tie-breaker.
  4. Return results ordered by property ID and tenant rank.

Schema

properties
ColumnTypeDescription
property_idPKINTUnique property identifier
property_nameVARCHAR(100)Property name
tenants
ColumnTypeDescription
tenant_idPKINTUnique tenant identifier
property_idINTProperty associated with the tenant
tenant_nameVARCHAR(100)Tenant full name
rent_payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
tenant_idINTTenant responsible for the payment
due_dateDATEContractual payment due date
paid_dateDATEDate the payment was received
payment_statusVARCHAR(20)Payment processing status
Tablespropertiestenantsrent_payments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results