google-bigquery - BigQuery,来自 DAU 的 WAU
问题描述
我正在尝试使用此链接从 DAU 计算 WAU:
修复在 Amazon Redshift 上计算 DAU 和 MAU 时的 MAU 问题
但是链接中的解决方案适用于 Redshift。我试图在 BigQuery 中做同样的事情,但它给了我这个错误:
LEFT OUTER JOIN cannot be used without a condition that is an equality of fields from both sides of the join
我的代码在这里:
WITH
data AS (
SELECT
EXTRACT(date FROM active_time) AS active_date,
COUNT(distinct user_id) AS DAU
FROM
abc
GROUP BY
active_date )
SELECT
active_date,
DAU,
(select count(distinct user_id)
from abc
where EXTRACT(date FROM abc.active_time) between DATE_SUB(data.active_date, interval 7 day) and data.active_date
) as WAU
from data
有人可以帮忙吗?TIA
解决方案
这是实现结果的一种方法(注意:通过 BQ 中的左连接相等性检查是一种平均黑客攻击,但它可以完成工作):
select
a.active_date,
count(distinct a.user) as dau,
array_length(array_agg(distinct b.user)) as wau
from abc a
left join data b on array_length(split(cast(a.active_date as string), '-')) = array_length(split(cast(b.active_date as string), '-'))
and b.active_date between date_sub(a.active_date, interval 1 day) and a.active_date
group by 1
推荐阅读
- vba - 用行/列变量编写一个While循环?
- python-3.x - 使用 df['C'] 与 df.loc[:, 'C'] 在 Pandas 数据框中分配新列
- regex - 查找以具有特定模式的下划线开头的单词的换行符
- python-3.x - 无法正确切片数据帧
- javascript - 在 sequelize 查询中比较时间戳和日期
- javascript - VueJS Instafeed 模板在特定图像上被忽略
- c++ - 在操作系统上独立运行 Qt QProcess
- arduino - ESP8266 UDP parsePacket 在做其他事情时不起作用
- linux - 需要将 jenkins 日志文件推送到 Amazon S3 存储桶
- javascript - 检查树是否展开或打开(Selenium / Python)