I have a table like this:
RunId------CompanyId------NumberOfEmployees
1-------------------1-------------------10
2-------------------1-------------------10
3-------------------1-------------------8
4-------------------1-------------------9
5-------------------1-------------------11* (The first time company 1 expands to a size bigger than it's original size of 10)
6-------------------1-------------------12
3-------------------2-------------------50
4-------------------2-------------------55* (The first time company 2 expands to a size bigger than it's original size of 55)
5-------------------2-------------------54
1-------------------3-------------------100
2-------------------3-------------------100
3-------------------3-------------------100
And I want to find for each CompanyID, what run did the company start expanding to a size that's bigger than its original starting size.
So I'd like to have a result set like this:
CompanyId------StartRun------ExpansionRun-------StartingSize
1-------------------1-------------------5-------------------10
2-------------------3-------------------4-------------------50
Thanks so much for your time in advance!
I have also done my research and found this answer Select rows where column value has changed, however this only compares the consecutive runs instead of comparing to the first run a company started.