title: T-SQL Time Averaging
body: <p>I have a table in SQL Server that stores statistics for a piece of hardware, rows in the table represent data for a given second. It contains for example, these columns:</p>
  
  <pre><code>timestamp (DateTime)
  value (int)
  </code></pre>
  
  <p>What I want to do is select the data from the table for a given date/time range but return it in such a way that it averages for a given time period (such as 1 minute, 5 minute, 1 day etc) between the given range. So for an hour I'd have 60 rows of 1 minute averages.</p>
  
  <p>Where do I start with this? Anybody any points or ideas?</p>