Hi,
I have the data needs to be backed fill based on historical data because the data is not consistent (some day it's populated and some day it's not)
Below I have two tables (Transaction table and Account_Location table):
We would like to backfill the transaction records that have blank account number with location information and join the account location history.
But we would like to pick up the most recent previous day account number (which is max(locn_d-1)) from historical data in account location history.
Then display how many days different from transaction date.
so the expected output after back fill would be
Thanks a lot for your help guys.
I have the data needs to be backed fill based on historical data because the data is not consistent (some day it's populated and some day it's not)
Below I have two tables (Transaction table and Account_Location table):
Code:
Transaction - capture daily transaction with account and location information.
TRAN_D ACCT_N LOCN_N TRAN_A
2018-02-08 1234 A123 125
2018-02-07 B123 125
2018-02-06 C123 100
2018-02-05 3456 D123 500
2018-02-04 B123 600
2018-02-03 C123 100
2018-02-02 5678 E123 100
2018-02-01 F123 200
Account_Location_Hist - capture historical account and location, The account and location are unique for each date
LOCN_D ACCT_N LOCN_N
2018-02-08 1234 A123
2018-02-07 9999 B123
2018-02-07 1234 A123
2018-02-06 8888 B123
2018-02-05 7777 C123
2018-02-03 6666 B123
2018-02-03 1234 A123
2018-02-02 4444 C123
2018-02-02 1234 A123
2018-02-01 1234 A123
2018-01-30 3333 F123
2018-01-29 2222 F123
We would like to backfill the transaction records that have blank account number with location information and join the account location history.
But we would like to pick up the most recent previous day account number (which is max(locn_d-1)) from historical data in account location history.
Then display how many days different from transaction date.
so the expected output after back fill would be
Code:
Transaction - capture daily transaction with account and location information.
TRAN_D ACCT_N LOCN_N TRAN_A DATE_DIFF
2018-02-08 1234 A123 125
2018-02-07 [COLOR=#EF2929]8888[/color] B123 125 1 -- (picked up from 2018-02-06)
2018-02-06 [COLOR=#EF2929]7777[/color] C123 100 1 -- (picked up from 2018-02-05)
2018-02-05 3456 D123 500
2018-02-04 [COLOR=#EF2929]6666[/color] B123 600 1 -- (picked up from 2018-02-03)
2018-02-03 [COLOR=#EF2929]4444[/color] C123 100 1 -- (picked up from 2018-02-02)
2018-02-02 5678 E123 100
2018-02-01 [COLOR=#EF2929]3333[/color] F123 200 2 -- (picked up from 2018-01-30)
Thanks a lot for your help guys.