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
Complex SQL Scenarios
00:00
5 left

Complex SQL Scenarios

HardSQL · PostgreSQL

Problem

Tell me about a time you solved a complex SQL problem with multiple scenarios and edge cases.

For this SQL exercise, demonstrate that ability by reconciling eligible orders against settled payments and completed refunds. Handle unmatched records, duplicate payments, irrelevant statuses, zero values, and NULLs explicitly.

Output

  1. One row per customer and order month with a nonzero payment discrepancy.
  2. Columns: customer_name, order_month, gross_order_value, paid_amount, refunded_amount, net_value, payment_gap, and discrepancy_rank.
  3. Ignore orders with a NULL customer or order date, and rows with NULL monetary values. Sort by customer ID and month.

Schema

customers
ColumnTypeDescription
customer_idPKINTCustomer identifier
customer_nameVARCHAR(100)Customer display name
orders
ColumnTypeDescription
order_idPKINTOrder identifier
customer_idINTCustomer who placed the order
order_dateDATEOrder placement date
order_statusVARCHAR(30)Current order status
order_amountNUMERIC(12,2)Gross order amount
payments
ColumnTypeDescription
payment_idPKINTPayment transaction identifier
order_idINTRelated order identifier
payment_statusVARCHAR(30)Payment processing status
amountNUMERIC(12,2)Payment amount
refunds
ColumnTypeDescription
refund_idPKINTRefund transaction identifier
order_idINTRelated order identifier
refund_statusVARCHAR(40)Refund processing status
amountNUMERIC(12,2)Refund amount
Tablescustomersorderspaymentsrefunds
Interviewer

Your question is Complex SQL Scenarios. Start with the requirements and the four 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.