返回重新激活的用户teradata sql

ruoxqz4g  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(388)

我正在尝试形成一个查询,用于返回、重新激活和wau,定义如下:
返回wau-上周活跃
wau-上周不活跃,但最近30天内活跃
重新激活的wau–30天以上未出现
我有过去60天的表,包含客户id,登录日期,但不能滞后功能工作(teradata odbc连接)。我经常会遇到这样的错误:
[3706]语法错误:数据类型“logindate”与定义的类型名称不匹配。我的格式是:选择。。。。lag(logindate,1)over(按客户id顺序按1 asc划分)as lag\u ind from(。。。。
请帮我处理以上三种情况。

lhcgjxsq

lhcgjxsq1#

您可以聚合以获得预期答案:

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

关于滞后问题,在您重写之前,已在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,这里是文本值1,而不是第一列。

相关问题