I have a little trouble here.
If i have the following table:
ID | Name | ini_day
-----------------------
1 | Juan | 1
2 | Nora | 5
3 | Pepe | 9
4 | Lara | 12
5 | Alex | 18
6 | Lily | 20
I need to calculate the last day of work based in the next ini_day minus 1.
Expected result:
ID | Name | ini_day | end_day
------------------------------
1 | Juan | 1 | 4
2 | Nora | 5 | 8
3 | Pepe | 9 | 11
4 | Lara | 12 | 17
5 | Alex | 18 | 19
6 | Lily | 20 | NULL
How i achieve it? Thanks in advance!
2
Answers
On MySQL 8+, we can use the
LEAD()
window function:According to documentation of MYSQL
As a solution to above problem statement please try executing following SQL query.