gpt4 book ai didi

sql - Snowflake SQL 错误 - 函数 '-' : (TIMESTAMP_NTZ(9), TIMESTAMP_NTZ(9)) 的参数类型无效

转载 作者:行者123 更新时间:2023-12-05 02:10:45 28 4
gpt4 key购买 nike

当我尝试减去时间戳并执行窗口函数(leadlagpartition by)时出现此错误:

Invalid argument types for function '-': (TIMESTAMP_NTZ(9), TIMESTAMP_NTZ(9))

尝试过 date_diff,但这不能与窗口函数一起使用

SELECT 
user_id,
event,
received_at,
received_at - LAG( received_at,1) OVER (PARTITION BY user_id ORDER BY received_at) AS last_event
FROM
segment_javascript.help_center_opened

最佳答案

您不能通过仅减去两个日期来获得数字来使用“Oracle 方式”来完成此操作,您必须使用带有度量单位/比例的 diff 函数,例如:

SELECT 
ts,
TIMESTAMPDIFF(MILLISECONDS, LAG(ts, 1) OVER (ORDER BY ts), ts) tsd
FROM
(VALUES (CURRENT_TIMESTAMP), (DATEADD(DAY, 1, CURRENT_TIMESTAMP))) v(ts);

关于sql - Snowflake SQL 错误 - 函数 '-' : (TIMESTAMP_NTZ(9), TIMESTAMP_NTZ(9)) 的参数类型无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58276160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com