0

我正在尝试按移动平台收集过去未登录但可能已在报告周登录的用户计数。为此,我建立了两个虚拟表,带有reporting_date - 这是每周的星期六,cust_id、app_logins、mobile_platform,其中一个(newmob)收集所有具有app_logins = 0的cust_id,另一个(existmob)具有具有app_logins> 0的cust_id .

我的逻辑是使用 newmob 表中的所有 cust_ids 直到报告周的前一个星期六,并找到在报告周的星期六之前登录的任何 cust_ids,但它似乎没有工作。

表结构- newmob 报告日期 | 客户 ID | app_login (0) | mobile_os(空)

表结构-existmob reportingdate | 客户 ID | app_login (>0) | mobile_os(如安卓、iOS)

SQL: --to_char(last_day(trunc(add_months(trunc(current_date,'D')-1,-12),'D')), 'YYYY-MM-DD')是表中的最小日期

Select a.reportingdate, count(distinct a.cust_id) as cust_count, a.mobile_os
from existmob a
where a.reportingdate >= to_char(last_day(trunc(add_months(trunc(current_date,'D')-1,-12),'D')), 'YYYY-MM-DD') + 6
and a.CUST_ID in (select cust_ID from newmob b where b.reportingdate <= a.reportingdate -7)
group by 1,3;

任何帮助将不胜感激。

4

0 回答 0