问题
I want to find the days difference and populate a new column in my target table. The difference is created by subtracting the previous date from current date.
Please find the attached screen shot for reference.
Thanks.
回答1:
Using LAG function help you to get the previous row and DATEDIFF to get the difference.
select
id,
function_id,
key,
pre_date,
datediff(pre_date, lag(pre_date, 1) over(order by id)) as days_difference
from
[Your_Table]
来源:https://stackoverflow.com/questions/52831735/find-the-difference-in-days-from-previous-timestamp-in-hive