问题
I have a table with three columns (lending_id int, installment_n int, status text) and I wonder how to retrieve the value (int) of the biggest gap of NOK (status) per lending_id.
For the following example:
lending_id, installment_n, status
32882, 1, OK
32882, 2, OK
32882, 3, OK
32882, 4, OK
32882, 5, OK
32882, 6, OK
32882, 7, OK
32882, 8, NOK
32882, 9, OK
32882, 10, OK
32882, 11, NOK
32882, 12, NOK
32882, 13, NOK
32882, 14, OK
32882, 15, OK
32882, 16, NOK
32882, 17, NOK
32882, 18, NOK
32882, 19, NOK
32882, 20, NOK
32882, 21, NOK
32882, 22, NOK
32882, 23, OK
32882, 24, NOK
1005, 1, OK
1005, 2, NOK
1005, 3, NOK
1005, 4, NOK
1005, 5, OK
The result would be:
Lending_id = 32882 is 6 (from 16 to 22)
and Lendind_id = 1005 is 2 (from 2 to 4)
It's very close to this question but when I get NOK status at the bottom it does broke the result set.
来源:https://stackoverflow.com/questions/46897764/getting-biggest-interval-of-rows-with-same-value