如何获取同一列中两行之间的差异
Posted
技术标签:
【中文标题】如何获取同一列中两行之间的差异【英文标题】:How to get the difference between two rows in the same column 【发布时间】:2020-09-26 01:57:14 【问题描述】:这就是我到目前为止所拥有的,我正在尝试获取同一列中的行之间的差异。我想不通。我正在尝试在 clickhouse 中查询。
SELECT
session_id,
created,
DATEDIFF(mi, time1.created, time2.created)
FROM impressions as time1
LEFT JOIN impressions i2 as time2
ON time1.session_id = time2.session_id + 1
【问题讨论】:
究竟什么“不起作用”?你期待/想要什么,你得到了什么? 【参考方案1】:查询应该使用dateDiff-function:
SELECT
time1.session_id,
time2.session_id,
time1.created,
dateDiff('minute', time2.created, time1.created)
FROM impressions AS time1
LEFT JOIN impressions AS time2 ON time1.session_id = toInt32(time2.session_id + 1)
SETTINGS join_use_nulls = 1
【讨论】:
【参考方案2】:我认为 Clickhouse 中的语法是:
SELECT time1.session_id, time1.created,
DATEDIFF('minute', time2.created, time1.created)
FROM impressions time1 LEFT JOIN
impressions i2 time2
ON time1.session_id = time2.session_id + 1
【讨论】:
以上是关于如何获取同一列中两行之间的差异的主要内容,如果未能解决你的问题,请参考以下文章
MySQL Workbench中两行之间的差异,但未授权LAG
使用python返回excel中两个不同文件中两列之间的差异