Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Rank Tenants by Payment Timeliness
00:00
5 left

Rank Tenants by Payment Timeliness

MediumSQL · PostgreSQL

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
Interviewer

Your question is Rank Tenants by Payment Timeliness. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.