Compute Order-Level Payment Success Rate by Method and Day

Last updated: November 29, 2026

Quick Overview

Given a payments table where a customer may make several attempts against the same order, write SQL that reports, per day and payment method over the last 7 days, the number of orders, the number of attempts, and the share of orders that eventually succeeded.

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

0

0

0 solved


Given a payments table where a customer may make several attempts against the same order, write SQL that reports, per day and payment method over the last 7 days, the number of orders, the number of attempts, and the share of orders that eventually succeeded.

Razorpay reports success rate to merchants and tracks it internally per method, and the definition (attempt level vs order level) changes the number a lot. This screen checks basic aggregation and whether you notice that retries make attempt-level success rate look worse than the customer experience.

What the Interviewer Expects
  • Ask whether success is measured per attempt or per order
  • Collapse attempts to one row per order before computing the rate
  • Define which statuses count as success
  • Filter the date window correctly
  • Avoid integer division
Key Topics to Cover
SQL aggregation
CTEs
metric definition
success rate
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 exclude attempts the customer abandoned before reaching the bank page?
  • If a customer fails on UPI then pays by card, which method gets credit?
  • How would you flag hours where UPI success rate drops more than 5 points below its trailing average?
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

payments(id, order_id, method, status, created_at). Statuses include created, authorized, captured, failed. I will treat authorized or captured as success, since auto-captured payments p...

Approach

CTE collapses to one row per (order_id, method) with a success flag via MAX(CASE ...), attempt count and the day of the first attempt. The outer query groups by day and method. Multiply by 1.0 b...


Submit Your Answer
Markdown supported

Related Questions