I need to count the last few months a member has had a D status.
For example, I have the table below, where I have the months from February to August for 2 members.
| year_month | member_id | status |
|---|---|---|
| 2020_02 | 1010 | D |
| 2020_03 | 1010 | D |
| 2020_04 | 1010 | D |
| 2020_05 | 1010 | A |
| 2020_06 | 1010 | A |
| 2020_07 | 1010 | D |
| 2020_08 | 1010 | D |
| 2020_02 | 1030 | A |
| 2020_03 | 1030 | A |
| 2020_04 | 1030 | A |
| 2020_05 | 1030 | D |
| 2020_06 | 1030 | A |
| 2020_07 | 1030 | A |
| 2020_08 | 1030 | D |
I need to count the number of months a member has been in D status in a row. In this example the expected result would be:
| member_id | count status D |
|---|---|
| 1010 | 2 |
| 1030 | 1 |
For member 1010 I need to count July and August, because in June he had A status.
Can anyone help me, please?
I'm a beginner and I have no idea how I can do this.