Does anybody knows a simple way to create a pivot of this result:
This result is created with query:
I want to show it like columns should become rows i.e it should be:
Please suggest a simple and easy to follow solution.
Code:
[0-1] [1-2] [2-3] [3-4] 12 45 29 5
Code:
SELECT [0-1] = SUM(CASE WHEN AGE >= 0 AND AGE <= 1 THEN 1 ELSE 0 END), [1-2] = SUM(CASE WHEN AGE > 1 AND AGE <= 2 THEN 1 ELSE 0 END), [2-3] = SUM(CASE WHEN AGE > 2 AND AGE <= 3 THEN 1 ELSE 0 END), [3-4] = SUM(CASE WHEN AGE > 3 AND AGE <= 4 THEN 1 ELSE 0 END) FROM dbo.Persons
Code:
[0-1] 12 [1-2] 45 [2-3] 29
Comment