sqlsql-server-2008t-sqlgroup-by

How can I group time by hour or by 10 minutes?


Like when I do

SELECT [Date]
  FROM [FRIIB].[dbo].[ArchiveAnalog]
  GROUP BY [Date]

How can I specify the group period? I'm using MS SQL 2008.

I've tried this, both with % 10 and / 10.

SELECT MIN([Date]) AS RecT, AVG(Value)
  FROM [FRIIB].[dbo].[ArchiveAnalog]
  GROUP BY (DATEPART(MINUTE, [Date]) / 10)
  ORDER BY RecT

Is it possible to make Date output without milliseconds?


Solution

  • finally done with

    GROUP BY
    DATEPART(YEAR, DT.[Date]),
    DATEPART(MONTH, DT.[Date]),
    DATEPART(DAY, DT.[Date]),
    DATEPART(HOUR, DT.[Date]),
    (DATEPART(MINUTE, DT.[Date]) / 10)