Get records of employees who took 11 consecutive days off
P粉014218124
P粉014218124 2023-08-16 20:44:15
0
1
445
<p>I have an attendance record with fields for employee number, status and attendance date. I want to use SQL query to get those records of employees who have taken leave for 11 consecutive days. The condition is that if the employee's attendance status is leave, absence or unmarked attendance (a date record that does not exist in the attendance document) for 11 consecutive days, including weekends. </p> <p>The criteria can be a mixture of all statuses, i.e. leave, absence or unmarked attendance. </p>
P粉014218124
P粉014218124

reply all(1)
P粉893457026

This query finds employees who have "leave", "absent" or "unmarked" status in the attendance record for 11 consecutive days. It joins employee data with attendance data, filters for specific status and date range, groups the data and selects only those groups with record count of 11.

SELECT DISTINCT a.employee_code
FROM employees e
JOIN attendance a ON e.employee_code = a.employee_code
WHERE a.attendance_date BETWEEN a.attendance_date AND DATE_ADD(a.attendance_date, INTERVAL 10 DAY)
  AND a.status IN ('请假', '缺席', '未标记')
GROUP BY a.employee_code, a.attendance_date
HAVING COUNT(*) = 11;

If this query doesn't work for you, please share your pattern. If there are any errors in this query, please point it out.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!