Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Agents by Recovery Rate SQL

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

Your question is Top Agents by Recovery Rate SQL. 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

Paytm Operations needs to identify the most effective collection agents based on recovery performance. Assume the query runs on 2026-08-29, so the last calendar month is July 2026.

Write a PostgreSQL query to return the top 5 agents by collection recovery rate for cases assigned during July 2026.

Requirements

  1. Calculate recovery rate as successful July collections divided by the total assigned amount for July cases, multiplied by 100.
  2. Include agents with assigned July cases but no successful collections, while excluding agents with no assigned amount.
  3. Consider only payments with payment_status = 'SUCCESS' and a July 2026 payment date.
  4. Return the agent name, total assigned amount, total recovered amount, and recovery rate, ordered by recovery rate descending, then recovered amount descending, and agent ID ascending for deterministic ties.

Schema

agents
ColumnTypeDescription
agent_idPKINTUnique collection agent identifier
agent_nameVARCHAR(100)Collection agent's name
collection_cases
ColumnTypeDescription
case_idPKINTUnique collection case identifier
agent_idINTAgent assigned to the case
assigned_dateDATEDate the case was assigned
assigned_amountNUMERIC(12,2)Amount assigned for recovery
recovery_payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
case_idINTCollection case associated with the payment
payment_dateDATEDate the payment was received
payment_amountNUMERIC(12,2)Amount received in the payment
payment_statusVARCHAR(20)Payment processing status
payment_methodVARCHAR(30)Payment channel used
Tablesagentscollection_casesrecovery_payments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results