I am working with the following data
Name | Number | Stage
Bob | 101 | 1
James | 102 | 2
Chris | 57 | 5
James | 3 | 1
James | 76 | 1
Bob | 95 | 2
Bob | 18 | 2
Bob | 7 | 3
Bob | 11 | 5
Bob | 1 | 4
I would like to be able to have results outputted into a format similar to this if possible
Name | Stage1 | Stage2 | Stage3 | Stage4 | Stage5
Bob | 1 | 2 | 1 | 1 | 1
Chris | 0 | 0 | 0 | 0 | 5
James | 2 | 1 | 0 | 0 | 0
I know I can get the counts based on each of the stages grouped by the Name using the following
select distinct name, count(stage) [Stage1]
from table
where stage = 1
group by name
But I am lost as to how to combine it into a single result set grouped by name