1
我需要看一個數據倉庫,檢查一2型變正常工作噸-SQL測試數據倉庫的2型變化
我需要檢查vaild瞭解最新的一排是一樣的vaild從下一行的日期開始。
此檢查,以確保行已經結束也已經正確啓動
感謝,馬克
我需要看一個數據倉庫,檢查一2型變正常工作噸-SQL測試數據倉庫的2型變化
我需要檢查vaild瞭解最新的一排是一樣的vaild從下一行的日期開始。
此檢查,以確保行已經結束也已經正確啓動
感謝,馬克
以下涉及金博爾型維度表。
注意,這個假設
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 ;
你怎麼知道的下一行是什麼?你試過什麼了? – LittleBobbyTables 2011-01-26 12:06:53