How to Use TSQL Lead and Lag Functions in SQL Server

preview_player
Показать описание
In this episode, I’ll explain how to use the T-SQL Lead and Lag functions in SQL Server. This techniques is very handy for situations where you need to put values from the next or previous rows onto the current row for things like calculations in analytics, or just for workflow. If you ever needed to code this functionality on a platform that did not support such a function, you will definitely appreciate how easy it is to do here.

Want to work with me 1:1? Contact me today and book your free 20 min consultation!

Follow me on social media:

Get Microsoft Office including Access:

Got a YouTube Channel? I use TubeBuddy, it is awesome. Give it a try:

#TSQL #LeadandLagFunctions #SQL #SQLserver

Рекомендации по теме
Комментарии
Автор

Very cool. Been using MSSQL for ten years and had never even heard of these before!
Am going through your back catalog and appreciating these great gems!

TubeDude
Автор

Hi Sean, your video was super helpful in making me understand how lag works. I have a follow up question, am I able to use several columns in the partition? And how does adding addtl columns affect the lag output?

unusualsweets