【发布时间】:2017-08-23 16:25:43
【问题描述】:
我试图找出连续行中两个日期之间的差异。我在 hive 中使用窗口函数,即lag。
但不同之处,即输出格式应为hh:mm:ss。
例如:
- 日期 1 是
2017-08-15 02:00:32 - 日期 2 是
2017-08-15 02:00:20
输出应该是:
00:00:12
我尝试的查询:
select from_unixtime(column_name),
(lag(unix_timestamp(from_unixtime(column_name)),1,0)
over(partition by column_name)-
unix_timestamp(from_unixtime(column_name))) as Duration from table_name;
但这会将输出返回为12(在上面的示例中)。
更新
我已将该列存储在具有 bigint 数据类型的表中。时间采用纪元格式。我们在查询中使用 from_unixtime 将其转换为可读日期。时间戳中的示例值
1502802618 1502786788
【问题讨论】: