【发布时间】:2020-01-26 20:23:48
【问题描述】:
总的来说,我对 SQL 很陌生,以前没有处理过红移。我正在尝试进行一个查询,该查询在 postgresql 中完美运行。但是我在红移中遇到语法错误。查询是:
SELECT
test.table_1.user_id as user_id,
test.table_1.timestamp as start_session,
test.table_1.step_3 :: timestamp + interval '1 hour' as end_session,
test.table_1.step_3 :: timestamp + interval '1 hour' - test.table_1.timestamp :: timestamp as session_duration
FROM (SELECT *,
min(case when page = 'second_page' then timestamp end) OVER (partition by user_id order by timestamp desc rows between unbounded preceding and unbounded following) as step_2,
min(case when page = 'third_page' then timestamp end) OVER (partition by user_id order by timestamp desc rows between unbounded preceding and unbounded following) as step_3
FROM test.table_1) test.table_1
WHERE
test.table_1.page = 'first_page' AND
step_2 > test.table_1.timestamp AND
step_3 > step_2 AND
step_3 :: timestamp - step_2 :: timestamp < '1 hour' AND
step_2 :: timestamp - test.table_1.timestamp :: timestamp < '1 hour'
ORDER BY
user_id,start_session
错误是Error running query: syntax error at or near "." LINE 11: FROM test.vimbox_pages) test.vimbox_pages ^ 在行FROM test.table_1) test.table_1
我不明白那里有什么问题。
通过这个查询,我试图以某种顺序在阅读页面期间获取用户操作的会话列表。
将感谢任何帮助!
【问题讨论】:
-
将子查询的别名从
test.table_1更改为t1并在您的查询中使用它。 -
文档没有明确说明它也适用于别名,但我猜别名命名应该遵循相同的规则:docs.aws.amazon.com/redshift/latest/dg/r_names.html 它说:不包含引号和空格。
标签: sql amazon-redshift