LAG Function in SQL Server The LAG function is used to access previous row data along with current row data. This function was introduced in SQL Server 2012. Using this function is easy to compare values in the current row with values in the previous row. It is just the opposite of LEAD function. The syntax for LAG function is, LAG([scalar_expression], offset, default_value) OVER([partition_by_clause] [order_by_clause]) In LAG function partition_by_clause is optional, order_by_clause is required. You can specify any number of columns in the order_by_clause. The offset denotes the number of rows to lag. The default_value to return if the number of rows to lag goes beyond last row in a table or partition. If the default_value is not specified NULL is returned. In order to achieve this we are going to use "tbl_EmployeeDetails" table for our demo. CREATE TABLE [dbo].[tbl_EmployeeDetails]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [E...