我想使用 WITH 运算符从我生成的视图 ( foo.bar.cohort
) 中获取计数,然后可以使用它从我的主视图 ( foo.bar.retention_30d
) 中的数据中计算一个值。看起来这应该很简单,但是当我尝试执行以下查询时出现此错误:
无法识别的名称:total_users 在 [12:29]
这是查询:
#standardsql
WITH
total_users AS (
SELECT
COUNT(DISTINCT uid) as sum_users
FROM
`foo.bar.cohort`
WHERE
first_seen_date > '2016-12-31'
AND first_seen_date < '2017-02-01')
SELECT
ROUND(SUM(retained_users)/total_users.sum_users, 2) AS avg,
SUM(retained_users) AS retained,
SUM(active_users) AS active,
total_users.sum_users
FROM
`foo.bar.retention_30d`
WHERE
period = 27
AND (created_at > '2016-12-31'
AND created_at < '2017-02-01')
架构foo.bar.cohort
:
架构foo.bar.retention_30d
:
指针/提示是最受欢迎的。谢谢!