SQL - group time interval results

Given the table structure ( eventTime in seconds), I want to group the results by a given time frame:

For example: 5 minutes

 0 to 5: 1 5 to 10: 2 10 to 15: 3 ..... 

How can this be done in SQL Server 2012?

Thanks!

Florian

 CREATE TABLE [dbo].[evalHubSupply]( [evalHubSupplyId] [int] IDENTITY(1,1) NOT NULL, [projectId] [int] NOT NULL, [scenarioId] [int] NOT NULL, [iterationId] [int] NOT NULL, [evalExportId] [int] NOT NULL, [eventType] [varchar](50) NOT NULL, [eventTime] [int] NOT NULL, [stopId] [varchar](50) NOT NULL, [stopName] [varchar](50) NULL, [vehicleId] [varchar](50) NOT NULL, [transitLineId] [varchar](50) NULL, [transitRouteId] [varchar](50) NULL, [capacity] [int] NULL, [arrivalTimeAtStop] [int] NULL, [agentsOnBoard] [int] NULL) 

Sample data (1 hour interval):

https://dl.dropbox.com/u/481455/table_data.xlsx or https://dl.dropbox.com/u/481455/table_data_open.ods

The "Table Data" tab contains sample data from evalHubSupply. The Time Interval column calculates the interval (in this case, per hour) to which the Event belongs. The result tabs count how many events are associated with a particular interval.

+4
source share
1 answer

this will give the number of entries for every 5 minutes of the group

 select eventTime/5,count(*) from evalHubSupply group by eventTime/5 
+1
source

Source: https://habr.com/ru/post/1437757/


All Articles