答案 0 :(得分:1)
您可以使用conditional aggregation
select SourceID,
sum(case when month(FileReceivedDate)= 1 then 1 else 0 end ) as Jan,
sum(case when month(FileReceivedDate)= 2 then 1 else 0 end ) as Feb,
sum(case when month(FileReceivedDate)= 3 then 1 else 0 end ) as Mar,
sum(case when month(FileReceivedDate)= 4 then 1 else 0 end ) as Apr
from tab
group by SourceId