title: The Average Number of Rides Completed in 4 Hours
body: <p>I have a dataset with each ride having its own ride_id and its completion time. I want to know how many rides happen every 4 hours, on average.</p>
  <p>Sample Dataset:</p>
  <pre><code>dropoff_datetime    ride_id
  2022-08-27 11:42:02 1715
  2022-08-24 05:59:26 1713
  2022-08-23 17:40:05 1716
  2022-08-28 23:06:01 1715
  2022-08-27 03:21:29 1714
  </code></pre>
  <p>For example, I would like to find out between 2022-8-27 12 PM to 2022-8-27 4 PM how many rides happened that time? And then again from 2022-8-27 4 PM to 2022-8-27 8 PM how many rides happened in that 4 hour period?</p>
  <p>What I've tried:</p>
  <ol>
  <li>I first truncate my dropoff_datetime into the hour. (DATE_TRUNC)</li>
  <li>I then group by that hour to get the count of rides per hour.</li>
  </ol>
  <p>Example Query:
  Note: calling the above table - final.</p>
  <pre><code>SELECT  DATE_TRUNC('hour', dropoff_datetime) as by_hour 
  ,count(ride_id) as total_rides 
  FROM final 
  WHERE 1=1 
  GROUP BY 1 
  </code></pre>
  <p>Result:</p>
  <pre><code>by_hour total_rides
  2022-08-27 4:00:00  3756
  2022-08-27 5:00:00  6710
  </code></pre>
  <p>My question is:
  How can I make it so it's grouping every 4 hours instead?</p>