【发布时间】:2023-03-30 14:06:01
【问题描述】:
我对 Redshift 中的这个运行总和有疑问(使用 Postgres 8):
select extract(month from registration_time) as month
, extract(week from registration_time)%4+1 as week
, extract(day from registration_time) as day
, count(*) as count_of_users_registered
, sum(count(*)) over (ORDER BY (1,2,3))
from loyalty.v_user
group by 1,2,3
order by 1,2,3
;
我得到的错误是:
ERROR: 42601: Aggregate window functions with an ORDER BY clause require a frame clause
【问题讨论】:
-
您不能在窗口定义中使用列号作为排序依据(
(1,2,3)与1,2,3不同 - 不要使用无用的括号)。over (order by registration_time)应该做你想做的事 -
在使用
order by registration_time时仍然遇到同样的错误。我的sum函数本身的语法是否正确?
标签: sql postgresql sql-order-by aggregate-functions window-functions