← All SQL interview questions

Reconcile gateway payments with bank settlements

MediumJoins — Left/Right Outer JoinPayPalRazorpay

A finance team reconciles what the payment gateway recorded against what the bank actually settled. Money can be missing on either side.

Compare gateway_payments with bank_settlements on order_ref. Return only the exceptions: order_ref, gateway_amount, settled_amount and recon_status, where recon_status is:

  • MISSING_SETTLEMENT when the gateway has the order but the bank does not
  • UNEXPECTED_SETTLEMENT when the bank has it but the gateway does not
  • AMOUNT_MISMATCH when both have it but the amounts differ

Orders that match exactly must not appear. Order by order_ref.

Sample data

Table: gateway_payments

8 row(s)

payment_idINTorder_refTEXTamountNUMERIC(10,2)
1ORD-50011500.00
2ORD-50022300.00
3ORD-5003899.00
4ORD-50044200.00
5ORD-5005650.00
6ORD-50063100.00
7ORD-50071250.00
8ORD-5008780.00

Table: bank_settlements

8 row(s)

settlement_idINTorder_refTEXTsettled_amountNUMERIC(10,2)
1ORD-50011500.00
2ORD-50022300.00
3ORD-5003889.50
4ORD-5005650.00
5ORD-50063100.00
6ORD-5008780.00
7ORD-50091999.00
8ORD-5010520.00