Skip to content
Advertisement

Calculating a plug/balance in SQL

My current table has a few accounts which always have minimal values (example, X & Y for actual and AA, BB, CC & DD for plan) in current table. Accounts with minimal values can extend beyond these accounts. I need to categorize such accounts into proxy account called “balance” which would always be [final-(abc+def+ghi)](please refer to Expected table). I’m trying it difficult to construct this in SQL using sum (case when account not in ('abc','def','ghi').

Current tableand Expected results

Sample dataset here: http://sqlfiddle.com/#!9/114cfe/1

SQL attempt

Advertisement

Answer

I think it would be easier to split it into two steps. Change the values in one step and group the rows in another.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement