Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

sql lag

	 -- Employee --
------------------------
| 1 | Mae | 01.02.2018 |
| 2 | Jon | 15.04.2018 |
| 3 | Eve | 28.06.2018 |
------------------------

SELECT id, name, 
       Lag(DateColumn, 1) OVER(ORDER BY DateColumn ASC) AS EndDate
FROM @Employee;

-- Add new column and shift line + 1 of DateColumn
-------------------------------------
| 1 | Mae | 01.02.2018 | NULL		|
| 2 | Jon | 15.04.2018 | 01.02.2018 |
| 3 | Eve | 28.06.2018 | 15.04.2018 |
-------------------------------------

-- See the source for better explanation
Source by www.sqlshack.com #
 
PREVIOUS NEXT
Tagged: #sql #lag
ADD COMMENT
Topic
Name
1+5 =