已入职为例,参考着写离职
SELECT T.MONTH_,count(emp.工号) [入职数量] FROM (
select convert(varchar(7),dateadd(MONTH,number,DATEADD(MONTH,-11,GETDATE())),120)+'-26' as [MONTH_]
FROM master..spt_values
where type='P' and number>=0
and dateadd(MONTH,number,DATEADD(MONTH,-11,GETDATE()))<=GETDATE()
) T LEFT JOIN 人员表 EMP ON EMP.入职日期>=T.MONTH_ AND EMP.入职日期<=DATEADD(MONTH,1,T.MONTH_)
group BY T.MONTH_ ORDER BY 1 ASC