abc
abc

Reputation: 157

Find the difference in days from previous timestamp in hive

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.

Screenshot

Thanks.

Upvotes: 0

Views: 1032

Answers (1)

mohabbati
mohabbati

Reputation: 1158

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]

Upvotes: 1

Related Questions