I have a table with aggregated data that I would like to pivot. Here is a sample of the data:
Unit# EffectiveDay RequestCount ResponseCount 5 1 0 0 5 2 8 8 5 3 4 4 5 4 4 4 5 5 2 2 5 6 0 0 5 7 2 2 6 1 0 0 6 2 0 0 6 3 0 0 6 4 0 0 6 5 0 0 6 6 0 0 6 7 0 0
I can successfully pivot the RequestCount column, but when I add the ResponseCount column it's as if the rows increased exponentially. Instead of two rows (one for each unit#), I get 14.
select *
from (
select Unit#
,concat('Request', EffectiveDay) AS RequestDay
,RequestCount
,concat('Response', EffectiveDay) As ResponseDay
,ResponseCount
from #tmpLogPayConnexion
) as P
pivot (
sum(RequestCount)
for RequestDay in ([Request1], [Request2], [Request3], [Request4], [Request5], [Request6], [Request7])
) as pvtRequest
pivot (
sum(ResponseCount)
for ResponseDay in ([Response1], [Response2], [Response3], [Response4], [Response5], [Response6], [Response7])
) as pvtResponse
I know this is possible, but I am stumped.
Thank you.