I have to conduct a count of CONSECUTIVE occurrences by date of student absences.
Within two categories: 2 consecutive fouls/absences and 3 or more consecutive fouls.
Data example:
| Name | Date | Present |
|---|---|---|
| Student 1 | 2022/01/01 | false |
| Student 1 | 2022/01/02 | false |
| Student 1 | 2022/01/03 | true |
| Student 1 | 2022/01/04 | false |
| Student 1 | 2022/01/05 | false |
| Student 1 | 2022/01/06 | false |
| Student 1 | 2022/01/07 | true |
| Student 1 | 2022/01/08 | false |
| Student 1 | 2022/01/09 | false |
| Student 1 | 2022/01/10 | false |
| Student 1 | 2022/01/11 | false |
| Student 1 | 2022/01/12 | true |
| Student 1 | 2022/01/13 | false |
| Student 1 | 2022/01/14 | false |
| Student 1 | 2022/01/15 | true |
Expected outcome:
| Students | Count 2 Consecutive Absences | Count 3 consecutives or more | Total of Absences |
|---|---|---|---|
| Student 1 | 2 | 2 | 11 |
I tried to conduct this code using LAG and OVER, but I wasn't successful.
CASE WHEN LAG(present) OVER (order by date) is false AND present is false THEN 1 END as test
