title: How to Get Aggregate Data by Time Slice (sum, avg, min, max, etc.) in Rails 3
body: <p>How can I create active relation queries in Rails 3 that are aggregated by time slice?  </p>
  
  <p>I'd like to build queries that for every n minute interval can return min, max, avg, sum, count, for every sample of a counter with a particular name.</p>
  
  <pre><code>create_table "samples"  
      t.integer  "counter_id"  
      t.string "name"  
      t.float    "value"  
      t.datetime "created_at"  
  end  
  </code></pre>