【问题标题】:Presto- get timestamp difference预获取时间戳差异
【发布时间】:2019-04-20 12:54:16
【问题描述】:

我是 PrestoDB 的新手,想编写一个查询来比较两个时间戳, 第一行日期将与下一个日期行进行比较,如果差异大于 15 分钟,则打印该行。 我已经写了下面的查询,但是在执行它时抛出了错误: “函数 from_iso8601_timestamp 的意外参数(带时区的时间戳)”。

SELECT mt.logical_name, mt.cable_name, mt.dt, mt.met_date,       
date_diff('second', from_iso8601_timestamp(met_date),                 
lag(from_iso8601_timestamp(met_date)) over (order by met_date))
FROM MyTable mt
where mt.dt = 20181117 and mt.cable_name = 'cable' and mt.logical_name ='ABCD0000008'
ORDER BY mt.met_date;

到目前为止,还没有设置任何过滤条件来仅打印差异大于 15 分钟的那些行,并且我还想在进行比较时添加带有时间戳的 +10:00。 在这方面寻求一些帮助。 任何帮助将不胜感激。

【问题讨论】:

    标签: sql hive presto


    【解决方案1】:

    met_date 列不是 from_iso8601_timestamp 正在寻找的格式。:

    “2018-11-07 00:05:00”应为“2018-11-07T00:05:00”。

    作为一种快速修复,您可以将 from_iso8601_timestamp(met_date) 替换为 from_iso8601_timestamp(replace(met_date, ' ', 'T'))

    从您提供的初始查询中,您可以选择

    SELECT
      logical_name, cable_name, date_add('minute', 10, met_date) as met_date, time_difference
    FROM (
    
    SELECT mt.logical_name, mt.cable_name, mt.dt, mt.met_date,       
      date_diff('second', met_date,                 
      lag(met_date) over (order by met_date)) AS 
    time_difference
    FROM (
    
      SELECT mt.logical_name, mt.cable_name, mt.dt, 
      from_iso8601_timestamp(replace(met_date, ' ', 'T')) as met_date
      FROM MyTable mt
      where mt.dt = 20181117 and mt.cable_name = 'cable' and mt.logical_name 
      ='ABCD0000008'
    
       )
    )
    WHERE time_difference >= 15
      ORDER BY met_date DESC
    

    【讨论】:

      猜你喜欢
      • 2021-08-18
      • 1970-01-01
      • 2012-02-28
      • 2011-06-13
      • 2015-06-27
      • 2013-05-18
      • 2014-05-04
      • 2012-06-03
      • 1970-01-01
      相关资源
      最近更新 更多