SQL Server LAG LEAD
After using order by, can use LAG to feedback (up line) record and use LEAD to feedback (down line) record Example: return the number of items produced at each location for each week and the week before. Select location, week, itemsproduced, lag(itemsproduced) over (partition by location order by week) as previtemproduced from sites Example: return the number of items produced at each location for each week and the week next. Select location, week, itemsproduced, lead(itemsproduced) over (partition by location order by week) as previtemproduced from sites