考勤统计情况SQL语句

select
employeeId,
convert(varchar(10),occurred_date,120) as 天数,
sum(case when eventType=1 then 1 else 0 end ) as 出勤数,
sum(case when eventType=2 then 1 else 0 end ) as 迟到数,
sum(case when eventType=3 then 1 else 0 end ) as 早退数,
sum(case when eventType=4 then 1 else 0 end ) as 出差数
from record
where occurred_date between '开始时间' and '结束时间'
group by employeeId,convert(varchar(10),occurred_date,120)

你可能感兴趣的