I need a hint please, in my table it can happen that positions of an order is not written to the next ID.
Lets Look on the Table:
Pos 2 is missing in ID 3
ID | DOC | POSI | TOTAL |
---|---|---|---|
1 | 123 | 1 | 100 |
1 | 123 | 2 | 600 |
1 | 123 | 3 | 200 |
2 | 123 | 1 | 100 |
2 | 123 | 2 | 600 |
2 | 123 | 3 | 200 |
3 | 123 | 1 | 100 |
3 | 123 | 3 | 200 |
Is it possible to create a view using SQL that compares the individual IDs partitions with each other and appends the missing value from ID 2 to ID 3 as a row?
Maybe you have some keywords for me, if something like this is possible.
CodePudding user response:
with n as (
select *,
row_number() over (partition by by id order by posi) as rn
from T
)
select *
from n full outer join T
on T.id = n.id and T.posi = n.rn