【问题标题】:Calculate DAU, MAU and WAU计算 DAU、MAU 和 WAU
【发布时间】:2023-01-29 20:57:05
【问题描述】:

我有一个带有 user_id 和日期的 temp_table,我想找到 DAU 、 WAU 和 MAU ,我正在查询这个:
DAU - 当天的活跃用户数
WAU - 过去 7 天的活跃用户数
MAU - 过去 30 天的活跃用户数
其中日期从此处提到的日期开始,因此不能进行 current_date 比较。

dau as (Select casted_date, count(user_id) as dau 
from temp table 
group by casted_date)
select casted date, dau,
sum(dau) over (order by casted_date rows between -6 preceding and current row) as wau,
sum(dau) over (order by casted_date rows between -29 preceding and current row) as mau
from dau;

但是查询给我这样的错误:
“-”处或附近的语法错误.

PS:我在mysql中写查询

【问题讨论】:

  • cte 定义中缺少 WITH..
  • 还有其他 CITIE,因此不使用“with”,但谢谢我的错

标签: mysql sql


【解决方案1】:

我不知道您的查询逻辑是否完全正确,但您目前看到的语法错误是由于窗口函数调用造成的。考虑这个更正后的版本:

sum(dau) over (order by casted_date rows between 6 preceding and current row) as wau,
sum(dau) over (order by casted_date rows between 29 preceding and current row) as mau

不需要使用 -6 来引用前 6 行,因为 6 preceding 已经是这个意思了。

【讨论】:

  • 如果您认为还有另一种方法可以做到这一点,您能在这里提一下吗?这对我学习会有帮助
猜你喜欢
  • 2017-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-24
  • 1970-01-01
  • 2018-09-25
  • 1970-01-01
相关资源
最近更新 更多