title: SQL Group by Date Range
body: <p>I have the following data:</p>
  
  <pre><code>Date        Code
  2014-08-01  A
  2014-08-02  A
  2014-08-03  A
  2014-08-04  A
  2014-08-05  A
  2014-08-06  A
  2014-08-07  A
  2014-08-08  XXXX
  2014-08-09  XXXX
  2014-08-10  BB
  2014-08-11  CCC
  2014-08-12  CCC
  2014-08-13  CCC
  2014-08-14  CCC
  2014-08-15  CCC
  2014-08-16  CCC
  2014-08-17  CCC
  2014-08-18  XXXX
  2014-08-19  XXXX
  2014-08-20  XXXX
  2014-08-21  XXXX
  2014-08-22  XXXX
  2014-08-23  XXXX
  2014-08-24  XXXX
  2014-08-25  XXXX
  2014-08-26  XXXX
  2014-08-27  XXXX
  2014-08-28  XXXX
  2014-08-29  XXXX
  2014-08-30  XXXX
  2014-08-31  XXXX
  </code></pre>
  
  <p>I want to group the data with codes but also with date ranges so that the output becomes:</p>
  
  <pre><code>Min Date    Max Date    Code
  2014-08-01  2014-08-07  A
  2014-08-08  2014-08-09  XXXX
  2014-08-10  2014-08-10  BB
  2014-08-11  2014-08-17  CCC
  2014-08-18  2014-08-31  XXXX
  </code></pre>
  
  <p>I have thought about it but cannot think of how to group this data using SQL. Any ideas? Thanks!</p>