Back to questions

Final Account Balance PayPal SQL Interview Question

Final Account Balance

PayPal SQL Interview Question

Given a table containing information about bank deposits and withdrawals made using Paypal, write a query to retrieve the final account balance for each account, taking into account all the transactions recorded in the table with the assumption that there are no missing transactions.

Table:

Column NameType
transaction_idinteger
account_idinteger
amountdecimal
transaction_typevarchar

Example Input:

transaction_idaccount_idamounttransaction_type
12310110.00Deposit
12410120.00Deposit
1251015.00Withdrawal
12620120.00Deposit
12820110.00Withdrawal

Example Output:

account_idfinal_balance
10125.00
20110.00

Using account ID 101 as an example, $30.00 was deposited into this account, while $5.00 was withdrawn. Therefore, the final account balance can be calculated as the difference between the total deposits and withdrawals which is $30.00 - $5.00, resulting in a final balance of $25.00.

The dataset you are querying against may have different input & output - this is just an example!

Input

Output