Find the difference in days from previous timestamp in hive

…衆ロ難τιáo~ 提交于 2019-12-11 16:58:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!