Dies wird als eine grundlegende Art und Weise zur Verfügung gestellt Sie da Sie neu in SO zu erhalten begonnen. Sie müssen zweifellos die Logik ändern, die Sie als überlappend klassifizieren.
--your test data...
declare @table table (ID int, BeginTime datetime, EndTime datetime)
insert into @table (ID, BeginTime, EndTime) VALUES
(101,'7/4/2016','9/21/2016'),
(101,'8/8/2016','9/8/2016'),
(101,'9/8/2016','9/21/2016'),
(102,'9/2/2016','9/7/2016'),
(103,'9/22/2016','9/28/2016'),
(103,'9/23/2016','9/28/2016')
/*
In SQL 2012 onward use LEAD and LAG to compare rows to the ones above or below them
Change this logic as you need... based on the limited information for "overlapping"
I just placed a flag where the dates didn't light up perfectly. There are undoubtedly
more cases/better logic you will need.
*/
select
ID,
BeginTime,
EndTime,
case when lead(BeginTime) over (partition by ID order by BeginTime asc) <> EndTime then 'n' else 'y' end as toKeep
from @table
--This is the same logic applied in a CTE so we can update the table
;with cte as(
select
ID,
BeginTime,
EndTime,
case when lead(BeginTime) over (partition by ID order by BeginTime asc) <> EndTime then 'n' else 'y' end as toKeep
from @table)
--Update your table via the CTE
delete from cte where toKeep = 'n'
select * from @table
Blick in ROW_NUMBER() OVER (PARTITION BY ...) – Mihai
Sie sollten Datenschema zur Verfügung stellen und selbst etwas versuchen. – McNets
Ich habe mehrere Dinge selbst ausprobiert, kann aber nichts richtig arbeiten. – d142c681