【问题标题】:Returning reactivated users teradata sql返回重新激活的用户 teradata sql
【发布时间】:2020-10-30 21:01:31
【问题描述】:

我正在尝试为返回、重新激活和 WAU 形成查询,定义如下:

  • 返回 WAU - 上周活跃
  • WAU - 上周不活跃,但在过去 30 天内活跃
  • 重新激活的 WAU - 30 多天未见

我有过去 60 天的表格,其中包含 cust_id、登录日期,但无法延迟功能工作(Teradata ODBC 连接)。我不断收到此错误:

[3706] 语法错误:数据类型“logindate”与定义的不匹配 键入名称。我的格式是: select .... lag(logindate, 1) over (partition 按 cust_id order by 1 asc) as lag_ind from ( ....

请帮忙解决以上 3 种情况。

【问题讨论】:

    标签: sql teradata lag teradata-sql-assistant lead


    【解决方案1】:

    你可以聚合得到预期的答案:

    select cust_id,
       case
         when max(logindate) > current_date - 7  -- active last week
           then 'Returning WAU' 
         when max(logindate) > current_date - 30 -- not active last week, but active within last 30 days
           then 'WAU'
         else 'Reactivated WAU'                  –- not seen in 30+ days
       end
    from tab
    group by 1
    

    关于 LAG 的问题,这已经在 16.10 中引入,在你必须重写之前:

    lag(logindate, 1)
    over (partition by cust_id
          order by col asc) as lag_ind
    
    max(logindate)
    over (partition by cust_id
          order by col asc
          rows between 1 preceding and 1 preceding) as lag_ind
    

    提示:不要在 OLAP 函数中使用 ORDER BY 1,这里是字面值 one 而不是第一列。

    【讨论】:

    • 感谢@dnoeth 的帮助。这对每周报告没有帮助......基本上我已经将我的表格扩展到过去 3 个月,并试图在第 # | 周生成报告返回 WAU | WAU | 7 月 4 日重新激活 WAU(周六结束)| xxxx | xxx | xxxx
    猜你喜欢
    • 2021-10-30
    • 1970-01-01
    • 2011-08-26
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    相关资源
    最近更新 更多