SQL Server : select rows from each seconds -


i have table inserted information gps points on every 5 or 3 seconds

for example:

id  timestamp 1   2016-02-06 19:33:02   2   2016-02-07 19:33:07   3   2016-02-08 19:33:10   4   2016-02-09 19:33:15   5   2016-02-10 19:33:20   6   2016-02-11 19:33:23   7   2016-02-12 19:33:27   8   2016-02-13 19:33:32   9   2016-02-14 19:33:37   10  2016-02-15 19:33:40   11  2016-02-16 19:33:45   12  2016-02-17 19:33:48   13  2016-02-18 19:33:53   14  2016-02-19 19:33:56   15  2016-02-19 19:34:01   16  2016-02-19 19:34:05   17  2016-02-19 19:34:08   18  2016-02-19 19:34:11   19  2016-02-19 19:34:16   20  2016-02-19 19:34:21   21  2016-02-19 19:34:24   22  2016-02-19 19:34:29   23  2016-02-19 19:34:34   24  2016-02-19 19:34:37       

i want information every 30 seconds.

the result should this:

id  timestamp 1   2016-02-06 19:33:02   8   2016-02-13 19:33:32   15  2016-02-19 19:34:01   23  2016-02-19 19:34:34          

you can use grouping first id value of each 30-second interval:

select t1.id, t1.timestamp mytable t1 inner join (   select min(id) id         mytable   group cast(timestamp date),            datepart(hh, timestamp),            datepart(mi, timestamp),                     datepart(s, timestamp) / 30 ) t2 on t1.id = t2.id 

demo here


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -