我正在尝试撰写一份声明,用于计算员工出勤率,并通过计算重复id
来执行他们name
,id
以及他过去3个月工作的日期NewTimeAttendance
第1,第2和第3个月。
我试过数:
Select COUNT(employeeid)
from NewTimeAttendance
where employeeid=1 and (month=1 or month = 2 or month = 3)
这绝对有效,但仅适用于一名员工。
第二次尝试:
SELECT COUNT(NewEmployee.EmployeeID)
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and (month=1 or month =2 or month = 3)
这是有效的,但它会计算所有员工,我希望它将每个EmployeeId
,EmployeeName
和number of days
作为新记录执行。
最后一次尝试:(在看到代码之前......这是错误的..但我正在尝试)
for i in 0..27 loop
SELECT COUNT(NewEmployee.EmployeeID),NewEmployee.EmployeeId,EmployeeName
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID(i) = NewTimeAttendance.EmployeeID
and (month=1 or month =2 or month = 3)
end loop
我真的需要帮助......提前谢谢。
答案 0 :(得分:5)
您需要GROUP BY
功能,请尝试:
SELECT COUNT(NewEmployee.EmployeeID), NewEmployee.EmployeeId,EmployeeName
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and (month=1 or month =2 or month = 3)
GROUP BY NewEmployee.EmployeeID, EmployeeName