SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Get record count by time intervals
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mattluk
Starting Member

15 Posts

Posted - 09/29/2013 :  22:29:19  Show Profile  Reply with Quote
Our DB server stored a lot of job records.
Such as:
JobID   StartTime    EndTime
1000001    1/1/1900 17:01    1/1/1900 17:11
1000002    1/1/1900 17:11    1/1/1900 17:12
1000003    1/1/1900 17:12    1/1/1900 17:21
1000004    1/1/1900 17:13    1/1/1900 17:31
1000005    1/1/1900 17:20    1/1/1900 17:25


I would like to count by evey 10 mins.

The result like this
JobID   StartTime    EndTime
17:00    1
17:10    4
17:20    3
17:30    1
17:40    0


Anyone can give me a hand?

khtan
In (Som, Ni, Yak)

Singapore
17611 Posts

Posted - 09/30/2013 :  01:34:28  Show Profile  Reply with Quote
SELECT dateadd(minute, datediff(minute, 0, StartTime)/10*10, 0), COUNT(*)
FROM   . . .
GROUP BY dateadd(minute, datediff(minute, 0, StartTime)/10*10, 0)



KH
Time is always against us

Go to Top of Page

Lumbago
Norsk Yak Master

Norway
3271 Posts

Posted - 09/30/2013 :  07:53:10  Show Profile  Reply with Quote
http://thefirstsql.com/2010/06/23/finding-the-most-active-15-minute-time-period/

- Lumbago
My blog-> http://thefirstsql.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30219 Posts

Posted - 09/30/2013 :  08:39:12  Show Profile  Visit SwePeso's Homepage  Reply with Quote
StartTime and EndTime columns should be changed to TIME datatype.

ALTER TABLE dbo.Table1 ALTER COLUMN StartTime TIME(0) NOT NULL
ALTER TABLE dbo.Table1 ALTER COLUMN EndTime TIME(0) NOT NULL




Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/30/2013 :  09:56:11  Show Profile  Reply with Quote
see

http://visakhm.blogspot.in/2010/02/aggregating-data-over-time-slots.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000