Free SQL Pattern Training: https://etlsql.kartra.com/page/sps-fr...
Do you understand SQL but still cannot write SQL queries correctly ?
Are you afraid to switch jobs because of the SQL interview rounds or have you failed SQL Interview earlier ?
If you are someone who understands SQL and need more confidence to solve SQL queries correctly, I would like to share my recent online course especially created for you.
Check for more details: https://etlsql.kartra.com/page/sql-pa...
In this video I have solved SQL Question - Titled "Final Account Balance" on Data Lemur platform.
Data Lemur referral link for easy reference: https://bit.ly/3SuF3wf
Hope you like the way I am explaining my thought process.
Let me know if this is helping you to solve SQL queries more confidently and you wish me to share more such videos.
Question:
Given a table of bank deposits and withdrawals , return the final balance of each account.
Solution:
#############################
select account_id,
deposit_amount - withdrawal_amount as final_balance
from
(
select account_id,
sum(case when transaction_type='Deposit' then amount else 0 end) as deposit_amount,
sum(case when transaction_type='Withdrawal' then amount else 0 end) as withdrawal_amount
from
transactions
group by account_id
)t;
#############################