Here is my query
SELECT *
FROM requirementRange
PeakRange
,DaysOfReq
columns are nvarchar datatype and Total
You should be able to use something similar to the following:
select
peakrange,
coalesce([Day 0], 0) [Day 0],
coalesce([Day 1], 0) [Day 1],
coalesce([Day 2], 0) [Day 2],
coalesce([>2 Days], 0) [>2 Days],
peak_Total
from
(
select peakrange, daysofreq, total,
sum(total) over(partition by PeakRange) peak_Total
from requirementRange
) d
pivot
(
sum(total)
for daysofreq in ([Day 0], [Day 1], [Day 2],
[>2 Days])
) piv
order by peakrange;
See SQL Fiddle with Demo