答案 0 :(得分:0)
您可以尝试exists
:
select t.*
from t
where exists (select 1
from t t2
where t2.transactionId = t.transactionId and
t2.enddate > t.startdate and
t2.startdate < t.enddate and
-- and not the same record
t2.startdate <> t.startdate and
t2.enddate <> t.enddate
);
这样的查询短语如何?
select t.*
from t join
t t2
on t2.transactionId = t.transactionId
where t2.enddate > t.startdate and
t2.startdate < t.enddate and
t2.startdate <> t.startdate and
t2.enddate <> t.enddate
(如果您具有唯一的ID,则最后两个条件可以用该ID代替。)
如果可能的话,您可能想要select distinct
。