これをチェックしてください。間隔が重複していないため、これらの結果を返す簡単なSQLクエリを書くことができます。以下のSQLは、測定テーブルをシミュレートする@Eventsというダミーテーブル変数を作成します。最後のクエリは、1秒を超えるギャップを出力します(変数@MaxIntervalAllowedBetweenEventsで設定可能)。あなたのテーブルが既にそれにアイデンティティを持っている場合
-- table with dummy data
declare @Events table (
ID int IDENTITY NOT NULL,
StartDate datetime NOT NULL,
EndDate datetime NOT NULL
)
INSERT @Events VALUES ('1/1/2011 1:00am', '1/1/2011 2:00am')
INSERT @Events VALUES ('1/1/2011 2:00am', '1/1/2011 3:00am') -- no gap after previous event
INSERT @Events VALUES ('1/1/2011 3:01am', '1/1/2011 4:00am') -- 1 minute gap
INSERT @Events VALUES ('1/1/2011 4:30am', '1/1/2011 5:00am') -- 30 minute gap
-- this variable defines the maximum interval allowed between events
declare @MaxIntervalAllowedBetweenEvents int
set @MaxIntervalAllowedBetweenEvents = 1 -- # seconds
-- select the gaps between events
SELECT
e1.EndDate,
Min(e2.StartDate) as NextEventStartDate,
DateDiff(s, e1.EndDate, Min(e2.StartDate)) as SecondsBetweenEvents
FROM
@Events as e1
join
-- for each event in e1, get the event that immediately follows it
@Events as e2
on (e1.EndDate <= e2.StartDate)
GROUP BY
e1.EndDate
HAVING
-- filter out events that are too close to each other
(DateDiff(s, e1.EndDate, Min(e2.StartDate)) > @MaxIntervalAllowedBetweenEvents)
ORDER BY
e1.EndDate
測定時間は重複している可能性がありますか? – Keith
[シンプルトークのこの記事](http://www.simple-talk.com/sql/t-sql-programming/find-missing-date-ranges-in-sql/)を参照してください。 – Andomar
いいえ、いいえ時間が重なる – Curtis