title: MySql Select and Group by Open and Closing hrs in range
body: <p>I have a table that stores the open and close hours for a restaurant. I need a sql query to select the days in a range by status Open or Closed for a particular business. </p>
  
  <p>The table:</p>
  
  <pre><code>id tbl_index_id  dow       status starttime endtime
   1            1  Monday    Closed 
   2            1  Tuesday   Open   8.00      17.00
   3            1  Wednesday Open   8.00      17.00
   4            1  Thursday  Open   8.00      17.00
   5            1  Friday    Open   8.00      17.00
   6            1  Saturday  Open   8.00      17.00
   7            1  Sunday    Closed
  </code></pre>
  
  <p>The tabl_index_id is the foreign key for the restaurant. I know, funny name, but there is a reason for it.</p>
  
  <p>What I need is this:</p>
  
  <p>Open:
  <strong>Tuesday - Saturday: 08:00AM - 05:00PM
    Saturday  and Sunday: Closed</strong></p>
  
  <p>The only solution I could come up with is this:</p>
  
  <pre><code>SELECT DoW as openDays, start_time, end_time from tbl_businesshrs WHERE 
  tbl_businesshrs.tbl_index_id = 1 and status = 'Open' GROUP BY DoW 
  </code></pre>
  
  <p>Please help. I honestly cannot figure this one out.</p>