Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Balance Discrepancies
00:00
5 left

SQL for Balance Discrepancies

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify discrepancies between expected and actual user balances after a trade at Gemini. Use the users, expected_balances, and actual_balances tables. Include mismatches and records missing from either balance source.

Output

  1. One row per discrepancy, with user_id, email, trade_id, expected_balance, actual_balance, discrepancy_amount, and status.
  2. Include missing expected or actual balances, and sort by user_id, then trade_id.

Schema

users
ColumnTypeDescription
user_idPKINTGemini user identifier
emailVARCHAR(255)User email address
expected_balances
ColumnTypeDescription
user_idPKINTUser associated with the expected balance
trade_idPKINTTrade identifier
expected_balanceNUMERIC(18,2)Balance expected after the trade
actual_balances
ColumnTypeDescription
user_idPKINTUser associated with the actual balance
trade_idPKINTTrade identifier
actual_balanceNUMERIC(18,2)Balance recorded after the trade
Tablesusersexpected_balancesactual_balances
Interviewer

Your question is SQL for Balance Discrepancies. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.