问题描述
我需要获取下一行日期字段的date-1值。需要类似于“预期日期”列的结果。
![enter image description here](https://i.stack.imgur.com/nxBkq.png)
我尝试了滞后功能,但没有得到预期的结果。
解决方法
尝试使用配置单元lead
功能。 Lead函数为您提供下一行的日期值。获取下一行后,请使用date_add
或date_sub
减去1天。
SELECT
Date,coalesce(date_add(lead(Date,1) over(order by Date),-1),'9999-12-31') as expected_date
FROM
table
最后,您可以使用coalesce
将空行的最终行值默认为9999-12-31
。