I have this Table
,
I want the data grouped by year, as the following table show
I tried this codes
SELECT *
FROM
(
SELECT Year, Income
FROM Sales
) t
pivot
(
count([Income]) for[Income]in ([1],[2],[3])
) as event_count;
However I'm getting Null Values
Year 1 2 3
2015 0 0 0
What is best way to achieve the desired result? Please forgive me, the way I arranged the question as I'm new in this forum.