Следующее относится к таблице измерений Kimball типа 2.
Обратите внимание, что это предполагает
3000-01-01
как дату в далеком будущем для текущих записей. CustomerKey
- автоинкрементное целое число.
В этом примере должен быть представлен список строк с пропущенными или пропущенными следующими записями.
;
with
q_00 as (
select
CustomerKey
, CustomerBusinessKey
, rw_ValidFrom
, rw_ValidTo
, row_number() over (partition by CustomerBusinessKey order by CustomerKey asc) as rn
from dimCustomer
)
select
a.CustomerKey
, a.CustomerBusinessKey
, a.rw_ValidFrom
, a.rw_ValidTo
, b.CustomerKey as b_key
, b.CustomerBusinessKey as b_bus_key
, b.rw_ValidFrom as b_ValidFrom
, b.rw_ValidTo as b_ValidTo
from q_00 as a
left join q_00 as b on b.CustomerBusinessKey = a.CustomerBusinessKey and (b.rn = a.rn + 1)
where a.rw_ValidTo < '3000-01-01'
and a.rw_ValidTo != b.rw_ValidFrom ;
Также полезно
-- Make sure there are no nulls
-- for rw_ValidFrom, rw_ValidTo
select
CustomerKey
, rw_ValidFrom
, rw_ValidTo
from dimCustomer
where rw_ValidFrom is null
or rw_ValidTo is null ;
-- make sure there are no duplicates in rw_ValidFrom
-- for the same customer
select
CustomerBusinessKey
, rw_ValidFrom
, count(1) as cnt
from dimCustomer
group by CustomerBusinessKey, rw_ValidFrom
having count(1) > 1 ;
-- make sure there are no duplicates in rw_ValidTo
-- for the same customer
select
CustomerBusinessKey
, rw_ValidTo
, count(1) as cnt
from dimCustomer
group by CustomerBusinessKey, rw_ValidTo
having count(1) > 1 ;