Bigquery - 'Having' 未按预期工作

Bigquery - 'Having' does not work as expected

我有疑问:

SELECT date(date) as day, App, count(*) as cnt,
avg(cnt) over (partition by App) as avg_per_day

FROM [DATABASE]

group by date,two_hour, App

现在我基本上只想使用平均每天下载量超过 5 次的应用程序。但是,当我添加 having avg_per_day>5 时,我得到

Field 'avg_per_day' not found.

同样输入where avg(cnt) over (partition by App) > 5也不行。

我做错了什么?

我不想使用双倍 SELECT,因为每个查询都需要花钱,而且它们应该每小时 运行。

谢谢

OVER() 在 HAVING 步骤之后运行 运行 - 因此在 HAVING 阶段,列 avg_per_day 仍然不存在。

而不是:

SELECT date(date) as day, App, count(*) as cnt,
avg(cnt) over (partition by App) as avg_per_day
FROM [DATABASE]
group by date,two_hour, App
having avg_per_day>5

尝试:

SELECT day, App, cnt, avg_per_day
FROM (
SELECT date(date) as day, App, count(*) as cnt,
avg(cnt) over (partition by App) as avg_per_day
FROM [DATABASE]
group by date,two_hour, App
)
WHERE avg_per_day>5

成本方面应该是一样的。