PayPal's risk team wants to flag accounts whose running balance ever dropped below zero. The balance after a transaction is the sum of all that account's transactions up to and including it, processed in order of `txn_date`, with `txn_id` breaking ties on the same date. Deposits are positive amounts and withdrawals are negative. Return `account_id`, `first_negative_date` (the date of the first transaction after which the balance was below zero) and `lowest_balance` (the minimum running balance reached) for every account that ever went below zero. Order the results by `account_id` ascending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.