Ram_God
Ram_God

Reputation: 47

SQL Server query without using cursor

I have data in a table and need to populate the min and max range for the row number column.

This is my input table:

enter image description here

I would like to have the following output table result without using a cursor:

enter image description here

Upvotes: 0

Views: 49

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269633

Do you just want lag()?

select t.*,
       lag(rownumber, 1, 0) over (order by rownumber) as rownumber_min,
       rownumber as rownumber_max
from t;

Upvotes: 3

Related Questions