Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
SQL for Test Data Validation
00:00
5 left

SQL for Test Data Validation

MediumSQL · PostgreSQL

Problem

What SQL queries have you used to validate data during testing?

Using the supplied tables, write one query that identifies orders whose stored total does not agree with their item total or payment total. The query must also identify orders with no items or no payments.

Output

  1. One row per order that fails validation
  2. Columns: order_id, order_total, item_total, payment_total, and validation_status
  3. Include missing totals as zero in the output
  4. Order by order_id ascending

Schema

orders
ColumnTypeDescription
order_idPKINTUnique order identifier
order_totalNUMERIC(10,2)Stored total expected for the order
order_items
ColumnTypeDescription
item_idPKINTUnique order item identifier
order_idINTOrder associated with the item
line_totalNUMERIC(10,2)Total value of the item line
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
order_idINTOrder associated with the payment
payment_amountNUMERIC(10,2)Amount applied by the payment
Tablesordersorder_itemspayments
Interviewer

Your question is SQL for Test Data Validation. Start with the requirements and the three 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.