I am relatively new to SSMS. I am attempting to write a query to sum balances with specific account numbers, and then subtract the sum of the 2nd group from the sum of the first group. I am only concerned with the totals of the underlying balances, but need those balances based on the account numbers. Here's an example of how the data is structured:
AcctNo BAL
123 11
234 22
345 33
456 44
678 55
789 66
I would like to sum the balances of group one, and group 2, and subtract group 2 from group 1. My initial attempts were as follows:
Declare @Bal1 INT
Declare @Bal2 INT
Select @Bal1 = Sum(Bal)
From XXX
Where Acctno In ('123','234','345')
Select@Bal2 = sum(Bal)
From XXX
Where Acctno IN ('678','789')
@Bal1 - @Bal2
Any insight you can provide would be greatly appreciated. Thank you.