Hi
I have an SQL table that has info on reasons why Employees left our organization. I need to group the results for each reason and by the branch. Basically like this table
Here is my Query
select Centre, (resignationReason),
sum(case when Centre = 'BRANCH 1' then 1 else 0 end) as BRANCH1,
sum(case when Centre = 'BRANCH 2' then 1 else 0 end) as BRANCH2,
sum(case when Centre = 'BRANCH 3' then 1 else 0 end) as BRANCH3,
sum(case when Centre = 'BRANCH 4' then 1 else 0 end) as BRANCH4,
sum(case when Centre = 'BRANCH 5' then 1 else 0 end) as BRANCH5,
sum(case when Centre = 'BRANCH 6' then 1 else 0 end) as BRANCH6
from HR_Exit_Interview group by centre, ResignationReason
But this is how it's being returned:
Centre | ResignationReason | Branch1 | Branch2 | Branch3 | Branch4 | Branch5 | Branch6 |
---|---|---|---|---|---|---|---|
Branch 1 | NULL | 23 | 0 | 0 | 0 | 0 | 0 |
Branch 3 | NULL | 0 | 0 | 1 | 0 | 0 | 0 |
Branch 5 | NULL | 0 | 0 | 0 | 0 | 2 | 0 |
Branch 1 | Career Change | 5 | 0 | 0 | 0 | 0 | 0 |
Branch 4 | Career Change | 0 | 0 | 0 | 3 | 0 | 0 |
Branch 5 | Career Change | 0 | 0 | 0 | 0 | 1 | 0 |
Branch 1 | Increased salary | 3 | 0 | 0 | 0 | 0 | 0 |
Branch 5 | Increased salary | 0 | 0 | 0 | 0 | 1 | 0 |
Branch 1 | No longer wanted to teach | 4 | 0 | 0 | 0 | 0 | 0 |
Branch 5 | No longer wanted to teach | 0 | 0 | 0 | 0 | 1 | 0 |
Branch 1 | Working hours | 1 | 0 | 0 | 0 | 0 | 0 |
Branch 5 | Working hours | 0 | 0 | 0 | 0 | 2 | 0 |
Please Help...