Select the next greatest value from a column

Solution 1:

This can be done with a simple correlated sub-query:

select *, (
  select Min(t2.accountId) 
  from t t2 
  where t2.CompanyId=t.CompanyId and t2.accountId > t.accountId 
) as NextAccountId
from t;