在出勤情况中,我想统计在特定日期范围内准时离开的人数。为此,我需要全体员工在离开办公室时标记出他们的出席情况。如果一个员工至少登录两次(第一次进出,第二次进出),则应计入标记出勤的员工总数中。
SELECT Max(TIMESTAMP),COUNT(DISTINCT employee_id) totalCount FROM attendance , db2.psnl p WHERE Date(timestamp) BETWEEN STR_TO_DATE('14/05/2019', '%d/%m/%Y') AND STR_TO_DATE('14/05/2019', '%d/%m/%Y') AND employee_id=p.MyId AND p.PayRollOfficeId=3 GROUP BY DATE(TIMESTAMP) HAVING COUNT(employee_id) >=2
对于单个员工,此查询的修改版本按员工过滤器作为分组依据,因此当我们在任何日期对员工至少有2个条目时,count> = 2将返回行。
答案 0 :(得分:0)
查询查询返回每天至少登录两次的员工的记录
select
attendance_id,
max(timestamp) as last_entry_by_employee,
group_concat(timestamp),
count(*) as c
from
attendance
group by employee_id, date_format(timestamp, "%Y-%m-%d")
having c >= 2