sql - 如何从 Presto 中的前一行获取 date_diff?

标签 sql presto

我正在尝试从此数据中从 Presto 获取 diff_date

timespent | 2016-04-09T00:09:07.232Z | 1000          | general
timespent | 2016-04-09T00:09:17.217Z | 10000         | general
timespent | 2016-04-09T00:13:27.123Z | 250000        | general
timespent | 2016-04-09T00:44:21.166Z | 1144020654000 | general

这是我的查询

select _t, date_diff('second', from_iso8601_timestamp(_ts), SELECT from_iso8601_timestamp(f._ts) from logs f 
              where f._t = 'timespent'
               and f.dt = '2016-04-09'
               and f.uid = 'd2de01a1-8f78-49ce-a065-276c0c24661b'
               order by _ts)
from logs d
where _t = 'timespent'
and dt = '2016-04-09'
and uid = 'd2de01a1-8f78-49ce-a065-276c0c24661b'
order by _ts;

这是我得到的错误

Query 20160411_150853_00318_fmb4r failed: line 1:61: no viable alternative at input 'SELECT'

最佳答案

我想你想要lag() :

select _t,
       date_diff('second', from_iso8601_timestamp(_ts),
                 lag(from_iso8601_timestamp(f._ts)) over (partition by uid order by dt)
                )
from logs d
where _t = 'timespent' and dt = '2016-04-09' and
      uid = 'd2de01a1-8f78-49ce-a065-276c0c24661b'
order by _ts;

关于sql - 如何从 Presto 中的前一行获取 date_diff?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36552859/

相关文章:

python - 如何让 Athena/Presto 识别 parquet 索引

sql - Django 模型 - 外键作为主键

mysqldump 生成空表

带有子查询的 MySQL 条件更新

presto - 如何使用presto查询配置单元数据

sql - 在另一列中使用列别名

sql - 从 SQL Presto 中的日常字段创建新字段列

mysql - 循环或递归 SQL 查询

sql - 时间范围表 SQL Presto

cassandra - Prestodb cassandraType is null 错误