我正在使用如下代码点火器和考勤表:
attendance ID timestamp student_id status
1 01-01-20 1 P
2 01-01-20 2 P
3 02-01-20 1 P
4 02-01-20 2 A
5 03-01-20 1 P
6 03-01-20 2 A
7 04-01-20 1 H
8 04-01-20 2 H
9 05-01-20 1 P
10 05-01-20 2 A
我的目标是获取从今天起最近1个月内连续3天缺席的学生证,不包括中间的假期,如上表所示,学生证2应该是连续3天的学生证缺席,不包括1月4日的假期。
我正在将Apache / 2.4.23(Win32)OpenSSL / 1.0.2h PHP / 5.6.28与mysql一起使用。我已经能够连续三个缺席,但是当中间有个假期时,我找不到附近的工作。这是我现有的代码:
SELECT *,
CASE
WHEN (@studentID = student_id) THEN @absentRun := IF(status = A, 0, @absentRun + 1)
WHEN (@studentID := student_id) THEN @absentRun := IF(status = A, @absentRun + 1, 0)
END AS absentRun
FROM attendance
Where timestamp BETWEEN (CURRENT_DATE() - INTERVAL 1 MONTH) AND CURRENT_DATE() AND year='2019-2020'
ORDER BY student_id, timestamp;
我真的很感谢有人快速帮助我解决问题。我真的很希望有一个解决方案,因为我是第一次在这里发布帮助。预先感谢。