title: Grouping sequences of rows - BigQuery / SQL
body: <p>I need to group a sequence of rows that have the same value in one determinate field. For instance, I have a series of Selina Kyle's records between two Bruce Wayne's records. I need to group those records by username, but as long as they are in a immediate sequence. For instance, I have this table:</p>
  
  <p><code>
  |User        | Time |Date_In                |Date_Out            |
  |Bruce Wayne | 2793 |2017-08-30 09:55:52    |2017-08-30 10:42:25 |
  |Selina Kyle | 2430 |2017-08-30 10:42:25    |2017-08-30 11:22:55 |
  |Selina Kyle | 4461 |2017-08-30 11:22:55    |2017-08-30 12:37:16 |
  |Selina Kyle | 4356 |2017-08-30 12:37:16    |2017-08-30 13:49:52 |
  |Selina Kyle | 2295 |2017-08-30 13:49:52    |2017-08-30 14:28:07 |
  |Bruce Wayne | 2098 |2017-08-30 14:28:07    |2017-08-30 15:03:05 |
  </code></p>
  
  <p>I need to group it by username and sum time, but I need the Bruce Wayne records separetely, because they are not in a immediate sequence:</p>
  
  <p><code>
  |User          |Time    |Date_In               |Date_Out           |
  |Bruce Wayne   |2793    |2017-08-30 09:55:52   |2017-08-30 10:42:25|
  |Selina Kyle   |13542   |2017-08-30 10:42:25   |2017-08-30 14:28:07|
  |Bruce Wayne   |2098    |2017-08-30 14:28:07   |2017-08-30 15:03:05|
  </code></p>