title: How to get time period of multiple days in MySql
body: <p>I have a table that has timestamps of vehicle logs.</p>
  <p><strong>Table look like</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>vehicle_type</th>
  <th>action</th>
  <th>timestamp</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>4</td>
  <td>ENTRY</td>
  <td>22-08-01 00:08:47</td>
  </tr>
  <tr>
  <td>2</td>
  <td>4</td>
  <td>ENTRY</td>
  <td>22-08-01 00:20:17</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  <td>EXIT</td>
  <td>22-08-02 13:48:46</td>
  </tr>
  <tr>
  <td>4</td>
  <td>2</td>
  <td>EXIT</td>
  <td>22-08-02 14:18:54</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>I want how many vehicles entered or exited hourly on different days</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>hourly_time</th>
  <th>entered_count</th>
  <th>exit_count</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>22-08-01 00:00:00</td>
  <td>2</td>
  <td>0</td>
  </tr>
  <tr>
  <td>2</td>
  <td>22-08-01 01:00:00</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>3</td>
  <td>22-08-01 02:00:00</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>4</td>
  <td>.................</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>5</td>
  <td>.................</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>6</td>
  <td>22-08-02 13:00:00</td>
  <td>0</td>
  <td>1</td>
  </tr>
  <tr>
  <td>7</td>
  <td>.................</td>
  <td>0</td>
  <td>1</td>
  </tr>
  <tr>
  <td>8</td>
  <td>22-08-02 14:00:00</td>
  <td>0</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>I Tried this but didn't get the result what I want. By using below query it's only working for 24hrs (Single Day)</strong></p>
  <pre><code>SELECT EXTRACT(HOUR FROM timestamp) as hour, 
         SUM(IF(action = 'ENTER', 1, 0)) as enter_count, 
         SUM(IF(action = 'EXIT', 1, 0)) as exit_count 
  FROM vehicle_logs 
  WHERE timestamp &gt;= '2022-08-01 00:00:00' 
    AND timestamp &lt;= '2022-08-02 23:59:59' 
  GROUP BY EXTRACT(HOUR FROM timestamp);
  </code></pre>