I have following data set for data lake which is acting as source for Dimension where I want to migrate the history data in Dimension
For e.g.: image
Primarykey Checksum DateFrom Dateto ActiveFlag
1 11 01:00 03:00 False
1 22 03:00 05:00 False
1 22 05:00 07:00 False
1 11 07:00 09:00 False
1 11 09:00 12/31/999 TRUE
Please note that datalake
table have multiple columns which are not part of dimension so we are recalculating the checking show same value but datefrom
and dateto
with base as (
Select
Primary_key,
checksum,
first_value ( datefrom ) over ( partition by Primary_key ,checksum order by datefrom ) as Datefrom,
last_value ( dateto ) over ( partition by Primary_key ,checksum order by datefrom ) as Dateto,
rownumber () over ( partition by Primary_key ,checksum order by datefrom ) as latest_record
from Datalake.user)
select * from base where latest_record = 1
Data shown as
Primarykey Checksum DateFrom Dateto
1 11 01:00 12/31/999
1 22 03:00 07:00
But Expected out is
Primarykey Checksum DateFrom Dateto
1 11 01:00 03:00
1 22 03:00 07:00
1 11 07:00 12/31/999
I tried using multiple ways in single query but any good suggestions?