Я пытаюсь подсчитать, сколько раз [Идентификатор отслеживания] и [Идентификатор отслеживания1] появляются в таблице.
The result should look like this.
This works great when I use a group by function.
select [Group], datename(month,[date]) as Month, count([Tracking ID]) + count([Tracking ID1]) as [Number of Record]
from [Table]
group by
[Group],
datename(month,[date])
I need to use a pivot function. How do I modify the code below to get the desired results
select *
from
(
select
[Group], datename(month,[date]) as Month, (count([Tracking ID])over () + count([Tracking ID1]) over () ) as [Number of Record]
From
[Table]
) sourcetbl
pivot
(count([Number of Record])
for [Month] in ([June], [July])
) as pivotTable;
Currently, my query returns 2 instead of 4.
введите описание изображения здесь