By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
11 rows affected
| n | value | mx | nth_value | sometimes_mx_2 | imputed_second_max | second_max |
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | null | 1 | 1 |
| 2 | 4 | 4 | 1 | 1 | 1 | 1 |
| 3 | 4 | 4 | 2 | 4 | 4 | 4 |
| 4 | 6 | 6 | 1 | 4 | 4 | 4 |
| 5 | 4 | 6 | 3 | null | 4 | 4 |
| 6 | 8 | 8 | 1 | 6 | 6 | 6 |
| 7 | 7 | 8 | 1 | null | 7 | 7 |
| 8 | 6 | 8 | 2 | null | 6 | 7 |
| 9 | 5 | 8 | 1 | null | 6 | 7 |
| 10 | 7 | 8 | 2 | null | 7 | 7 |
| 11 | 8 | 8 | 2 | 8 | 8 | 8 |