I have a table
branch_no crncy_id Tax_1_Account Tax_1_Balance Tax_2_Account Tax_2_Balance
1 3 01-01-211515 0.000000 NULL NULL
1 3 01-01-230305 726910532.850000 NULL NULL
1 3 NULL NULL 01-01-240130 2019759.840000
1 3 01-01-240135 135117.090000 NULL NULL
1 3 NULL NULL 01-01-510170 2140859.810000
1 3 01-01-610501 0.000000 NULL NULL
1 3 01-01-610520 37285.000000 01-01-610520 37285.000000
2 3 01-02-211515 0.000000 NULL NULL
2 3 01-02-230305 14483229.720000 NULL NULL
2 3 NULL NULL 01-02-240130 85462.290000
2 3 01-02-240135 0.000000 NULL NULL
2 3 NULL NULL 01-02-510170 0.000000
2 3 01-02-610501 0.000000 NULL NULL
2 3 01-02-610520 284409497.000000 01-02-610520 284409497.3
3 3 01-03-211515 0.000000 01-03-211515 0.000000
3 3 01-03-230305 0.000000 01-03-230305 0.000000
3 3 NULL NULL 01-03-240130 0.000000
3 3 01-03-240135 0.000000 01-03-240135 0.000000
3 3 NULL NULL 01-03-510170 0.000000
3 3 01-03-610501 0.000000 01-03-610501 0.000000
3 3 01-03-610520 710.000000 01-03-610520 710.000000
What I seek with is updating any NULLs that existing into Tax_1_Account
, Tax_1_Balance
, Tax_2_Account
& Tax_2_Balance
with the value that in next row in case same group of branch_no
And Crncy_id
and keep NULL at the last group for Tax_1_Account
, Tax_1_Balance
Or Tax_2_Account
& Tax_2_Balance
and delete record if there are NULLS into the 4 columns ( Tax_1_Account
, Tax_1_Balance
, Tax_2_Account
& Tax_2_Balance
)
Expected result:-
branch_no crncy_id Tax_1_Account Tax_1_Balance Tax_2_Account Tax_2_Balance
1 3 01-01-211515 0.000000 01-01-240130 2019759.840000
1 3 01-01-230305 726910532.850000 01-01-510170 2140859.810000
1 3 01-01-240135 135117.090000 01-01-610520 37285.000000
1 3 01-01-610501 0.000000 NULL NULL
1 3 01-01-610520 37285.000000 NULL NULL
2 3 01-02-211515 0.000000 01-02-240130 85462.290000
2 3 01-02-230305 14483229.720000 01-02-510170 0.000000
2 3 01-02-240135 0.000000 01-02-610520 284409497.000000
2 3 01-02-610501 0.000000 NULL NULL
2 3 01-02-610520 284409497.000000 NULL NULL
3 3 01-03-211515 0.000000 01-03-211515 0.000000
3 3 01-03-230305 0.000000 01-03-230305 0.000000
3 3 01-03-240135 0.000000 01-03-240130 0.000000
3 3 01-03-610501 0.000000 01-03-240135 0.000000
3 3 01-03-610520 710.000000 01-03-510170 0.000000
3 3 NULL NULL 01-03-610501 0.000000
3 3 NULL NULL 01-03-610520 710.000000
Thanks.
1条答案
按热度按时间lp0sw83n1#
You can do something like this perhaps:
Note, i create manual identity field (id) which ensures "correct" sort, but you probably have some other field like date which should be used to sort this table.
The rest of logic is following. I create two separate tables (type = 1 and type 2), that i sort by non-null values, and then i pivot them together to create the necessary final result.
having max(x.value) is not null
removes the completely empty rows that occur after moving up