Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get data basis on Minutes and Hour

Author  Topic 

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2010-01-15 : 04:36:21
i have some data which comes in every 1 min in my table and this comes for 24 hours a day.
I like to get data which is group by every 10 mins.
Like...
Seq count datetime
1 78 2010-01-01 00:02:00.000
2 54 2010-01-01 00:04:00.000
3 21 2010-01-01 00:06:00.000
4 21 2010-01-01 00:08:00.000
5 7 2010-01-01 00:10:00.000
6 54 2010-01-01 00:12:00.000
7 48 2010-01-01 00:14:00.000
8 48 2010-01-01 00:16:00.000
9 47 2010-01-01 00:18:00.000
10 78 2010-01-01 00:20:00.000

Then output must be like
Time Count
2010-01-01 00:10:00.000 181
2010-01-01 00:20:00.000 275

thhis will go for whole day?

iF theRe iS a wAy iN tHen theRe iS a wAy oUt..

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-15 : 04:40:35
[code]select dateadd(mi,((datediff(mi,0,datetime)-1/10) + 1)*10,0),sum([count]) as [count]
from table
group by dateadd(mi,((datediff(mi,0,datetime)-1/10) + 1)*10,0)
order by dateadd(mi,((datediff(mi,0,datetime)-1/10) + 1)*10,0)
[/code]
Go to Top of Page
   

- Advertisement -