1、SQL按季度统计分析
select datepart(year,checkdate) [年],
sum(case datepart(quarter,checkdate) when 1 then 1 else 0 end ) [第一季度],
sum(case datepart(quarter,checkdate) when 2 then 1 else 0 end ) [第二季度],
sum(case datepart(quarter,checkdate) when 3 then 1 else 0 end ) [第三季度],
sum(case datepart(quarter,checkdate) when 4 then 1 else 0 end ) [第四季度],
sum(1) 全年
from carcheck
group by datepart(year,checkdate)
2、Access按季度统计分析
select year(checkdate) as 年,
sum(iif(datepart('q',checkdate)=1,1,0)) as [第一季度],
sum(iif(datepart('q',checkdate)=2,1,0)) as [第二季度],
sum(iif(datepart('q',checkdate)=3,1,0)) as [第三季度],
sum(iif(datepart('q',checkdate)=4,1,0)) as [第四季度],
sum(1) as 全年
from carcheck
group by year(checkdate)