0

我有一个表,其中的条目使用 SCD 2 进行历史记录现在我正在寻找一种可能性来获得同时有效的 Alle PK:

例如我的表看起来像这样:

PK;ValidFrom;ValidTo
635582110901;2016-01-04;2016-01-21
635582110901;2016-01-22;2016-01-26
635582110901;2016-01-27;2016-02-14
635582110901;2016-02-15;2016-11-10
**635582110901;2016-11-11;2017-01-23**
**635582110901;2016-11-16;2016-12-12**
635582110901;2016-12-13;2017-01-18
635582110901;2017-01-19;2017-01-22
635582110901;2017-01-23;2017-01-23
635582110901;2017-01-24;2017-02-21
635582110901;2017-02-22;9999-12-31

选择应该给我两个粗体行

感谢您的帮助

4

1 回答 1

0

您可以使用exists

select t.*
from t
where exists (select 1
              from t t2
              where t2.validfrom < t.validto and
                    t2.validto > t.validfrom and
                    t2.pk = t.pk and
                    t2.validfrom <> t.validfrom and
                    t2.validto <> t.validto
             );
于 2017-07-01T22:38:05.447 回答