Cloud Stack Ninja

I am trying to join a table on itself, but on the next row (sorted by Empno).

Example data:

Empno  Work_hours  Max_Hours Empno
1       5            7
3       6           12
4      14           16

I need to compare the data of each employee with the next employee.

I need the result like this:

Empno  Work_hours  Max_hours  Empno   Work_hours   Max_hours
1       5            7         3        6           12
3       6           12         4       14           16
4      14           16         NULL    NULL         NULL

I am working in SQL Server and I have tried multiple things using ROW_NUMBER() but I can't get the result as I described above.

Read more here:

Content Attribution

This content was originally published by Joost Kaal at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: