Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

pivot sum

$
0
0

Hi,

I'm trying to aggregate the values which are pivoted by this query, so that column 2 is the sum of column1 + column2, and column 3 is the sum of column1 + colum2 + column3. I want to add yesterday, last 3 days and last 7 days together. Is this possible?

here's my query

SELECT*

FROM

(

SELECT JobPK, [GROUP+2], [dispatch Period]

FROM [vw_Gala SLA Report 2]

)ASsource

PIVOT

(

   Count(JobPK)

   FOR [dispatch Period] IN([A: Yesterday], [B: Last 3 Days], [C: Last 7 Days])

)as pvt

current result is:

GROUP+2 A: Yesterday B: Last 3 Days C: Last 7 Days
2                              0            1                 0
2+                            0            0               0
0                              5           47              61
1                            45           119          160

so really I want last 3 days to say 1,0,52 and 164 respectively.


Viewing all articles
Browse latest Browse all 23857

Trending Articles