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
Get started
Audit Account Balances Against Posted Ledger Entries
00:00
5 left

Audit Account Balances Against Posted Ledger Entries

MediumSQL · PostgreSQL

Problem

Explain your strategy for database consistency in a highly concurrent environment.

Write a PostgreSQL query that audits stored account balances against their posted ledger entries. Treat credits as positive, debits as negative, ignore non-posted entries, and safely handle NULL amounts.

Output

  1. One row per inconsistent account, including account_id, currency, opening_balance, current_balance, expected_balance, and difference.
  2. Include only accounts whose stored balance differs from the calculated balance, ordered by account_id ascending.

Schema

accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
currencyVARCHAR(3)ISO currency code
opening_balanceNUMERIC(18,2)Balance before ledger activity
current_balanceNUMERIC(18,2)Stored current account balance
ledger_entries
ColumnTypeDescription
entry_idPKINTUnique ledger entry identifier
account_idINTAccount affected by the entry
entry_typeVARCHAR(30)Ledger event type
amountNUMERIC(18,2)Monetary amount of the entry
statusVARCHAR(20)Processing status of the entry
Tablesaccountsledger_entries
Interviewer

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

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.