У меня есть следующая таблица:
CREATE TABLE #times
(
num int,
atime datetime
)
INSERT #times VALUES (1, '8/27/2015 1:10:00');
INSERT #times VALUES (1, '8/27/2015 1:10:15');
INSERT #times VALUES (1, '8/27/2015 1:10:28' );
INSERT #times VALUES (2, '7/3/2018 2:20:50' );
INSERT #times VALUES (2, '7/3/2018 2:21:05' );
INSERT #times VALUES (2, '7/3/2018 2:21:10' );
INSERT #times VALUES (2, '7/3/2018 2:30:55' );
INSERT #times VALUES (3, '1/1/2018 10:20:25');
INSERT #times VALUES (4, '1/1/2018 10:20:05');
INSERT #times VALUES (5, '9/15/2015 2:20:55');
Я бы хотел сгруппировать по num и atime в течение 30-секундного интервала, затем отметить максимальное время с 0 и другие времена в группе с 1.
Таким образом, результирующий набор данных будет таким:
1 '8/27/2015 1:10:00' 1
1 '8/27/2015 1:10:15' 1
1 '8/27/2015 1:10:28' 0 <<this is the max time of the grouping within num and 30 secs
2 '7/3/2018 2:20:50' 1
2 '7/3/2018 2:21:05' 1
2 '7/3/2018 2:21:10' 0 <<this is the max time of the grouping within num and 30 secs
2 '7/3/2018 2:30:55' 0
3 '1/1/2018 10:20:25' 0
4 '1/1/2018 10:20:05' 0
5 '9/15/2015 2:20:55' 0