Return To Origin Rate By Courier Partner And State

Last updated: November 29, 2026

Quick Overview

Given a shipments table with courier_id, dest_state, payment_mode and status (DELIVERED, RTO, RTO_IN_TRANSIT, IN_TRANSIT, and others), write SQL that reports the RTO rate per courier and destination state, overall and for cash on delivery orders only.

Meesho
Data Manipulation (SQL/Python)
Data Scientist
Meesho
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a shipments table with courier_id, dest_state, payment_mode and status (DELIVERED, RTO, RTO_IN_TRANSIT, IN_TRANSIT, and others), write SQL that reports the RTO rate per courier and destination state, overall and for cash on delivery orders only.

Return to origin shipments are one of the largest cost leaks in Meesho's cash on delivery heavy business, and logistics teams compare courier partners lane by lane. The interviewer checks that you pick the right denominator, use conditional aggregation, and do not let unresolved shipments distort a rate.

What the Interviewer Expects
  • Uses only resolved shipments (delivered or RTO) in the denominator
  • Counts RTO_IN_TRANSIT as an RTO outcome
  • Computes the COD-only rate with conditional aggregation in the same query
  • Guards against division by zero with NULLIF
  • Mentions a minimum volume filter before ranking
Key Topics to Cover
conditional aggregation
rate denominators
NULLIF
logistics metrics
COD
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compare couriers fairly when one serves far harder pincodes than the other?
  • How would you show the trend week by week without counting a shipment twice?
  • Which statuses would you check with the logistics team before trusting the numbers?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

shipments(shipment_id, order_id, courier_id, dest_state, payment_mode, status, created_at), one row per shipment with its latest status. I confirm that RTO_IN_TRANSIT means the buyer refused and t...

Approach

RTO rate = RTO outcomes / resolved shipments. Including in-transit rows in the denominator would make a courier with a backlog look better, so I exclude them. I compute both rates with SUM(CASE ...)...


Submit Your Answer
Markdown supported

Related Questions