title: time interval period in sql
body: <p>How to display the time period of the most widely in use in ms sql server</p>
  
  <p>I have purchase data, such as:</p>
  
  <pre><code>hours   the number of purchases
  10:00       2
  12:00       4
  13:00       5
  14:00       1
  </code></pre>
  
  <p>I want to show the period of time with most buyers. So the results would be with the most purchases hour period between 12:00 to 13:00.</p>
  
  <p>Here is my query :</p>
  
  <pre><code>select  h.hours, day(d.dates)
  from hours h, dates d
  group by h.hours, day(d.dates)
  having count(h.hours) &gt;= all (select count(h2.hours) 
  from hours h2, dates d2
  group by h2.hours, day(d2.dates))
  </code></pre>
  
  <p>but the result is: 13:00</p>
  
  <p>Can anyone help me?</p>