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.
| Author |
Topic |
|
mike123
Master Smack Fu Yak Hacker
1462 Posts |
Posted - 2008-08-21 : 11:15:12
|
| Hi,I have a log table that records certain events. I'd like to be able to run a query on it to find out which are the most "active" hours of the day.How can I do this?I'd like the data to look something like thisHourOfDay / totalViolations0 / 01 / 32 / 83 / 34 / 95 / 15etc on to 23Any help is much appreciated !Thanks,mike123CREATE TABLE [dbo].[tblSpamReports_KeyWord_Violations]( [spamReportID] [int] IDENTITY(1,1) NOT NULL, [offendingID] [int] NOT NULL, [dateViolated] [datetime] NOT NULL) ON [PRIMARY] |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-08-21 : 11:23:19
|
| [code]SELECT [HourOfDay] = DATEPART(hour,yourColumn) ,[Violations] = sum(violations)FROM yourTableGROUP BY DATEPART(hour,yourColumn)ORDER BY HourOfDay[/code]Jim |
 |
|
|
|
|
|