By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Records: 16 Duplicates: 0 Warnings: 0
| seqno | gap | (select sum(t1.seqno < t.seqno and t1.gap = "End") from tbl t1) + 1 |
|---|---|---|
| 20 | Start | 1 |
| 21 | End | 1 |
| 29 | Start | 2 |
| 30 | End | 2 |
| 42 | Start | 3 |
| 43 | End | 3 |
| 49 | Start | 4 |
| 50 | Start | 4 |
| 51 | Start | 4 |
| 52 | Start | 4 |
| 53 | Start | 4 |
| 54 | Start | 4 |
| 55 | End | 4 |
| 220 | Start | 5 |
| 221 | Start | 5 |
| 222 | End | 5 |