title: SQL - combine rows conditionally on the value of previous row
body: <p>My issue I believe is best explained by using an example:</p>
  <p>Sample Data</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>SO</th>
  <th>Customer</th>
  <th>Product</th>
  <th>Description</th>
  <th>Quantity</th>
  <th>Extension</th>
  <th>Country</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>01</td>
  <td>xxx</td>
  <td>123</td>
  <td>Product A</td>
  <td>01</td>
  <td>20.00</td>
  <td>USA</td>
  </tr>
  <tr>
  <td>02</td>
  <td>yyy</td>
  <td>456</td>
  <td>Product B</td>
  <td>02</td>
  <td>25.00</td>
  <td>China</td>
  </tr>
  <tr>
  <td>02</td>
  <td>yyy</td>
  <td>456</td>
  <td>Product B</td>
  <td>01</td>
  <td>12.50</td>
  <td>China</td>
  </tr>
  <tr>
  <td>02</td>
  <td>yyy</td>
  <td>789</td>
  <td>Product C</td>
  <td>01</td>
  <td>50.00</td>
  <td>Mexico</td>
  </tr>
  <tr>
  <td>03</td>
  <td>zzz</td>
  <td>789</td>
  <td>Product C</td>
  <td>01</td>
  <td>50.00</td>
  <td>Mexico</td>
  </tr>
  <tr>
  <td>03</td>
  <td>zzz</td>
  <td>789</td>
  <td>Product C</td>
  <td>01</td>
  <td>50.00</td>
  <td>Mexico</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Desired output:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>SO</th>
  <th>Customer</th>
  <th>Product</th>
  <th>Description</th>
  <th>Quantity</th>
  <th>Extension</th>
  <th>Country</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>01</td>
  <td>xxx</td>
  <td>123</td>
  <td>Product A</td>
  <td>01</td>
  <td>20.00</td>
  <td>USA</td>
  </tr>
  <tr>
  <td>02</td>
  <td>yyy</td>
  <td>456</td>
  <td>Product B</td>
  <td>03</td>
  <td>37.50</td>
  <td>China</td>
  </tr>
  <tr>
  <td>02</td>
  <td>yyy</td>
  <td>789</td>
  <td>Product C</td>
  <td>01</td>
  <td>50.00</td>
  <td>Mexico</td>
  </tr>
  <tr>
  <td>03</td>
  <td>zzz</td>
  <td>789</td>
  <td>Product C</td>
  <td>02</td>
  <td>100.00</td>
  <td>Mexico</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>So the key issue I'm having is grouping by the SO, then if there are duplicate lines of Product, consolidating lines into one. In the real data, there could be many lines to summarize or none at all - it could all be unique.</p>