我想构建一个查询,显示我的员工每天工作的次数。例如,我想表明,在一段时间内,吉姆工作了12个星期六,3个星期一和星期四。我打算通过从时钟条目中提取工作日datepart来做到这一点。我只是不知道如何构建它,以便有七个条件计数列。
提前致谢
答案 0 :(得分:0)
做出很多假设:
select
EmployeeID,
count(case when datepart(weekday, [timestamp]) = 1 then 1 end) as [Sunday],
count(case when datepart(weekday, [timestamp]) = 2 then 1 end) as [Monday],
count(case when datepart(weekday, [timestamp]) = 3 then 1 end) as [Tuesday],
count(case when datepart(weekday, [timestamp]) = 4 then 1 end) as [Wednesday],
count(case when datepart(weekday, [timestamp]) = 5 then 1 end) as [Thursday],
count(case when datepart(weekday, [timestamp]) = 6 then 1 end) as [Friday],
count(case when datepart(weekday, [timestamp]) = 7 then 1 end) as [Saturday]
from [TimeCard]
group by EmployeeID