I have a simple table with buildID (UUID, not int), Repository, the date, and the result:

```
BuildID     Repository  BuildDateTime         Result
------------------------------------------------------
1234        Repo1       2017-01-02T01:23:56   Fail
2224        Repo1       2017-01-02T01:22:56   Fail
3234        Repo1       2017-01-02T01:20:56   Success
4234        Repo2       2017-01-01T01:20:00   Fail
5234        Repo2       2017-01-01T01:19:00   Success
6234        Repo2       2017-01-01T01:18:00   Success
7234        Repo3       2017-01-01T01:17:30   Success
8234        Repo2       2017-01-01T01:17:00   Success

```

I am wanting to determine, for each build, how many consecutive builds in a row that the repository's build has had the same result, and when it started the streak. I want to put this into a view so the results look like this:

```
BuildID  Repository  BuildDateTime         Result   Streak   StreakStartDateTime
-------------------------------------------------------------------------------
1234     Repo1       2017-01-02T01:23:56   Fail     2        2017-01-02T01:22:56
2224     Repo1       2017-01-02T01:22:56   Fail     1        2017-01-02T01:22:56
3234     Repo1       2017-01-02T01:20:56   Success  1        2017-01-02T01:20:56
4234     Repo2       2017-01-01T01:20:00   Fail     1        2017-01-01T01:20:00
5234     Repo2       2017-01-01T01:19:00   Success  3        2017-01-01T01:17:00
6234     Repo2       2017-01-01T01:18:00   Success  2        2017-01-01T01:17:00 
7234     Repo3       2017-01-01T01:17:30   Success  1        2017-01-01T01:17:30
8234     Repo2       2017-01-01T01:17:00   Success  1        2017-01-01T01:17:00

```

I've been experiementing with the lag function, which helps me understand the previous X rows. The problem is that the number of rows I need to go back to find the results varies from row to row. I am beginning to think it is a dead end.

Any help is appreciated.