By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
| id | position | value |
|---|---|---|
| 5 | senior | 10000 |
| 6 | senior | 20000 |
| 8 | senior | 30000 |
| 9 | junior | 5000 |
| 4 | junior | 7000 |
| 3 | junior | 10000 |
| 1 | junior | 7000 |
INSERT 0 7
| id | position | value | cum_sum |
|---|---|---|---|
| 5 | senior | 10000 | 10000 |
| 6 | senior | 20000 | 30000 |
| 8 | senior | 30000 | 60000 |
| 9 | junior | 5000 | 65000 |
| 4 | junior | 7000 | 79000 |
| 1 | junior | 7000 | 79000 |
| 3 | junior | 10000 | 89000 |
SELECT 7
| id | position | value | cum_sum | strike |
|---|---|---|---|---|
| 5 | senior | 10000 | 10000 | 0 |
| 6 | senior | 20000 | 30000 | 0 |
| 8 | senior | 30000 | 60000 | 30000 |
| 9 | junior | 5000 | 65000 | 5000 |
| 4 | junior | 7000 | 79000 | 7000 |
| 1 | junior | 7000 | 79000 | 7000 |
| 3 | junior | 10000 | 89000 | 10000 |
SELECT 7
| id | position | value | row_number |
|---|---|---|---|
| 5 | senior | 10000 | 1 |
| 6 | senior | 20000 | 2 |
| 8 | senior | 30000 | 3 |
| 9 | junior | 5000 | 4 |
| 4 | junior | 7000 | 5 |
| 1 | junior | 7000 | 7 |
| 3 | junior | 10000 | 6 |
SELECT 7
| id | position | value | cum_sum | is_hired | next_i |
|---|---|---|---|---|---|
| 5 | senior | 10000 | 10000 | t | 2 |
| 6 | senior | 20000 | 30000 | t | 3 |
| 8 | senior | 30000 | 30000 | f | 4 |
| 9 | junior | 5000 | 35000 | t | 5 |
| 4 | junior | 7000 | 42000 | t | 6 |
| 1 | junior | 7000 | 49000 | t | 7 |
| 3 | junior | 10000 | 49000 | f | 8 |
SELECT 7
| juniors | seniors |
|---|---|
| 3 | 2 |
SELECT 1
INSERT 0 8
| id | position | value | cum_sum | is_hired | next_i |
|---|---|---|---|---|---|
| 11 | senior | 1 | 1 | t | 2 |
| 10 | senior | 1111 | 1112 | t | 3 |
| 5 | senior | 10000 | 11112 | t | 4 |
| 6 | senior | 20000 | 31112 | t | 5 |
| 8 | senior | 30000 | 31112 | f | 6 |
| 12 | senior | 40000 | 31112 | f | 7 |
| 17 | senior | 60000 | 31112 | f | 8 |
| 14 | junior | 100 | 31212 | t | 9 |
| 13 | junior | 500 | 31712 | t | 10 |
| 9 | junior | 5000 | 36712 | t | 11 |
| 4 | junior | 7000 | 43712 | t | 12 |
| 16 | junior | 7000 | 43712 | f | 13 |
| 1 | junior | 7000 | 43712 | f | 14 |
| 3 | junior | 10000 | 43712 | f | 15 |
| 15 | junior | 50001 | 43712 | f | 16 |
SELECT 15
| juniors | seniors |
|---|---|
| 4 | 4 |
SELECT 1
| position | count |
|---|---|
| junior | 6 |
| senior | 2 |
SELECT 2
| chek_jun | chek_sen |
|---|---|
| 7 | 4 |
SELECT 1