title: Retrieve first and last entry of hour with MySQL
body: <p>I have database to storing temperatures. There are three to five temperatures per hour and i want to get first and last temperature of an hour but i can't create suitable subquery.</p>
  
  <p>Here is the main query to get temperatures by hour.</p>
  
  <pre><code>SELECT HOUR(time) AS h, max(temp_in) as max, min(temp_in) as min, count(temp_in) as count 
  FROM tbl_temps 
  GROUP BY h; 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1VIJY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1VIJY.jpg" alt="enter image description here"></a></p>