Skip to content
Advertisement

Aggregate values at hourly interval using SQL server query

I have below test data in the table

I have written below SQL query to aggregate the values at hourly interval

currently getting results as

What should be my SQL query , If i want the hourly aggregation to consider from 15th minute instead of 0th minute .

Like first hour should have aggregation of

And the results should look like

Advertisement

Answer

The following expression will map the dates such as 2019-10-21 00:15, 2019-10-21 00:30, 2019-10-21 00:45 and 2019-10-21 01:00 to 2019-10-21 00:15:

Use this expression in your GROUP BY.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement