select year(入职日期),
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end 季度
,avg(datediff(year,getdate(),入职日期)) 平均年龄
from A
group by year(入职日期),
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end 季度
,avg(datediff(year,getdate(),入职日期)) 平均年龄
from A
group by year(入职日期),
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end
avg(datediff(year,生日,入职日期)) 平均年龄 from 表A
group by cast(datepart(year,入职日期) as varchar(4))+'Q'+cast(datepart(qq, 入职日期) as char)
select cast(datepart(year,入职日期) as varchar(4))+'Q'+cast(datepart(qq, 入职日期) as char) 季度,
avg(datediff(year,生日,入职日期)) 平均年龄 from 表A
group by cast(datepart(year,入职日期) as varchar(4))+'Q'+cast(datepart(qq, 入职日期) as char)
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end 季度
,avg(datediff(year,getdate(),入职日期)) 平均年龄
from A
group by year(入职日期),
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end
select year(入职日期),
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end 季度
,avg(datediff(year,入职日期,getdate())) 平均年龄
from A
group by year(入职日期),
,case when month(入职日期) between 1 and 3 then Q1
when month(入职日期) between 4 and 6 then Q2
when month(入职日期) between 7 and 9 then Q3
when month(入职日期) between 9 and 12 then Q4
end