sql server - How to find records that are more than 5 mins after the record before it in sql -
given table "recorded" date time field.
how can select records have recorded date/time more 5 mins after record before when table sorted recorded. or put way, gaps between records greater 5 min.
at moment doing in c# iterating on set , comparing record n record n+ 1.
is possible sql, preferably out using cursor?
how cte approach.
with mrows ( select *, row_number() on (order recorded) rn table_name ) select * mrows mr1 inner join mrows mr2 on mr1.rn = mr2.rn - 1 datediff(mm, mr1.recorded, mr2.recorded) = 5;
Comments
Post a Comment