我有一个包含三列的表(lending_id int,installment_n int,status text),我想知道如何检索每个lending_id的最大缺口NOK(状态)的值(int)。
对于以下示例:
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
结果将是:
Lending_id = 32882 is 6 (from 16 to 22)
and Lendind_id = 1005 is 2 (from 2 to 4)
它非常接近this question,但当我在底部获得NOK状态时,它确实打破了结果集。