source table:

Date Temperature NumMesurements 2018-11-04 07:00:00.000 21,1 1 2018-11-04 08:00:00.000 21,2 3 2018-11-04 09:00:00.000 21,4 2 2018-11-04 10:00:00.000 21,6 4 2018-11-04 11:00:00.000 21,2 5 2018-11-04 12:00:00.000 21,2 1 2018-11-04 13:00:00.000 21,2 1 

How to get the result over the time range (for example, from 8 to 12) for 2 hours to look like:

 конец двухчасовки средняя_температура количество измерений 2018-11-04 10:00:00.000 21,3 5 2018-11-04 12:00:00.000 21,4 9 

Base I use MS Sql server.

  • group by cast(date as date), datepart(hour, date)/2 - Mike
  • and what is your database? - Yaroslav
  • @Mike Thank you for what you need - Vova Afanasiev
  • @Yaroslav I use the base MS Sql server. - Vova Afanasiev
  • @Mike. Please tell me, if you specify a time range from 8-12 with the grouping you proposed, the result is 2018-11-04 10: 00: 00.000 21.3 5 2018-11-04 12: 00: 00.000 21.4 9 but if you specify the range from 9-13 it turns out 2018-11-04 09: 00: 00.000 21.4 2 2018-11-04 10: 00: 00.000 21.3 5 2018-11-04 12: 00: 00.000 21.4 9 2018-11 -04 13: 00: 00.000 21.2 1 how to adapt correctly so that the beginning of time does not play a role? - Vova Afanasiev

0