the Q: Mysql Counting the consecutive number rows that match has touched on this but would like some help expanding it.
I have multiple Members in a payments table and need a count of most recent Failed Payments where:
1 = Success, 2 = Fail
It must be based on most recent payments, not overall count! So a person could have had failures but count would be zero if most recent payment was Successful.
CREATE TABLE Payment
(`pID` int, `memID` int, `pStatus` int, )
;
INSERT INTO Payment
(`pID`, `memID`, `pStatus)
VALUES
(1, 1, 1001),
(2, 1, 1001),
(3, 1, 1001),
(4, 2, 1001),
(5, 2, 1001),
(6, 1, 1002),
(7, 2, 1002),
(8, 2, 1002),
(9, 1, 1002),
(10, 1, 1002),
(11, 2, 1003),
(12, 1, 1003),
(13, 2, 1003),
(14, 1, 1003),
(15, 2, 1003),
(16, 2, 1004),
(17, 2, 1004),
(18, 2, 1004),
(19, 2, 1004),
(20, 2, 1004);
Retun should be:
memId | failCount
1001 | 2
1002 | 0
1003 | 1
1004 | 5