BigQuery - 计算日期后 7 天内的唯一事件

BigQuery - Count Unique Events Within 7 Days of Date

Fiddle

我希望实现的是一个查询,该查询将计算在当前活动(包括其自身)的 7 天内存在多少个唯一活动。在 fiddle 中,我手动添加了一列来显示输出应该是什么,但是如何使用 Send_DateCampaign 列生成列 Sent_Within_7_Days

我试过混合使用 window 语句 mixed 和 case 语句,但没有骰子。

您可以使用以下内容。我不能说它更有效(但更清洁)(它还取决于 table 大小),但对于您的目的,没有更有效的方法。:

select Send_Date new_date, Campaign, Sent_Within_7_Days,
(select count(1) from Table1 where (send_date > date_sub(new_date,interval 7 day) 
and send_date <= new_date )) sw_7days from Table1;

测试here