在蜂巢中找到与上一个时间戳记相差天数 [英] Find the difference in days from previous timestamp in hive

查看:61
本文介绍了在蜂巢中找到与上一个时间戳记相差天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到天差并在我的目标表中填充一个新列.差异是通过从当前日期中减去前一个日期来创建的.

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.

谢谢.

推荐答案

使用LAG函数可帮助您获取上一行,而DATEDIFF可帮助您获取不同之处.

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]

这篇关于在蜂巢中找到与上一个时间戳记相差天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆