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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Failure Rate by Method and Segment
00:00
5 left

Failure Rate by Method and Segment

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate the daily failure rate by payment method and merchant segment for the last 90 days on a payment platform. Use the supplied transaction and reference tables. Treat a transaction with status FAILED as a failure, and retain records whose payment method or merchant segment is unavailable.

Output

  1. One row per transaction date, payment method, and merchant segment within the last 90 days.
  2. Columns: transaction_date, payment_method, merchant_segment, total_transactions, failed_transactions, and failure_rate.
  3. Return failure_rate as a percentage rounded to two decimal places, ordered by date descending, payment method, and merchant segment.

Output details

  • Treat DATE '2026-09-15' as today's date.
  • Include transactions from 2026-06-17 inclusively through before 2026-09-16.
  • Replace unavailable payment methods and merchant segments with UNKNOWN.
  • Order payment methods and merchant segments ascending after ordering transaction dates descending.

Schema

payment_transactions
ColumnTypeDescription
transaction_idPKINTUnique payment transaction identifier
occurred_atTIMESTAMPTimestamp when the transaction occurred
payment_method_idINTPayment method reference
merchant_idINTMerchant reference
statusVARCHAR(20)Transaction outcome
payment_methods
ColumnTypeDescription
payment_method_idPKINTUnique payment method identifier
method_nameVARCHAR(40)PhonePe payment method label
merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
segment_nameVARCHAR(40)Merchant business segment
Tablespayment_transactionspayment_methodsmerchants
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.