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
SQL for Data Manipulation
00:00
5 left

SQL for Data Manipulation

MediumSQL · PostgreSQL

Problem

How would you approach a tricky SQL problem to correctly transform and validate the results?

Use the provided transaction, adjustment, account, and expected-result tables. Produce one row for each latest settled transaction, calculate its adjusted amount, and identify whether the result is valid, mismatched, incomplete, or associated with an unknown account.

Output

  1. Return transaction_id, account_name, net_amount, expected_amount, variance, and validation_status.
  2. Include only the latest settled record for each transaction and exclude canceled transactions.
  3. Sort by transaction_id ascending.

Schema

transaction_events
ColumnTypeDescription
event_idPKINTUnique source event identifier
transaction_idVARCHAR(20)Business transaction identifier
account_idVARCHAR(20)Account associated with the transaction
version_numberINTSource version for the transaction
statusVARCHAR(20)Transaction processing status
gross_amountNUMERIC(12,2)Original transaction amount
loaded_atTIMESTAMPTime the source event was loaded
transaction_adjustments
ColumnTypeDescription
adjustment_idPKINTUnique adjustment identifier
transaction_idVARCHAR(20)Transaction receiving the adjustment
adjustment_typeVARCHAR(20)Fee, refund, credit, or other adjustment type
adjustment_amountNUMERIC(12,2)Signed adjustment amount
accounts
ColumnTypeDescription
account_idPKVARCHAR(20)Unique account identifier
account_nameVARCHAR(100)Account display name
expected_transaction_results
ColumnTypeDescription
transaction_idPKVARCHAR(20)Transaction being validated
expected_amountNUMERIC(12,2)Reference amount expected after adjustments
Tablestransaction_eventstransaction_adjustmentsaccountsexpected_transaction_results
Interviewer

Your question is SQL for Data Manipulation. 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.