I\'m in a weird situation with my query. My objective is to display the total deposits and withdrawals from multiple transactions for each person and display them. I am getting
Solution using Subquery
select t.lastname, t.firsname,sum(t.Withdrawal) Withdrawal ,sum(t.Deposit) Deposit,t.description from(
select lastname, firsname,
isnull(case when upper(category) = 'W' then abs(principal) end,0) as Withdrawal,
isnull(case when upper(category) = 'D' then abs(principal) end,0) as Deposit,
description
from table1 join
table2
on table2.id = table1.id join
table3
on table3.c = table2.c
where description = 'string'
)t group by t.lastname, t.firstname, t.description, t.category