Reputation: 111
I need to get the date-1 value of next row date field. Need result similar to column "Expected Date".
I tried lag function but not getting the expected result.
Upvotes: 0
Views: 450
Reputation: 3968
Try using hive lead
function. Lead function give you the next row date value. Once you get the next row, use date_add
or date_sub
to subtract 1 day.
SELECT
Date,
coalesce(date_add(lead(Date,1) over(order by Date), -1),'9999-12-31') as expected_date
FROM
table
Finally, you can use coalesce
to default the final row value to 9999-12-31
for the null row.
Upvotes: 1