今天有数据分析问我,如何动态统计过去30的数?比如0601,计算0502——0601的用户数去重,0602,计算0503——0602内的用户数去重,是个动态的30天用户数
他用的spark line。具体的语法的不熟悉,但是逻辑类似,利用循环控制传入的值即可
这里利用oracle的存储过程实现
create or replace procedure test2 is
v_date date;
begin
v_date := trunc(sysdate - 365);
while v_date<=sysdate loop
insert into t4 select count(distinct id),v_date from t3 where day_date>=trunc(v_date-30) and day_date<=v_date;
commit;
v_date := v_date+1;
end loop;
end;
这样即可实现,每一天统计从当天到当天往前30天的数据。

本文介绍了一种使用Oracle存储过程实现动态统计过去30天内去重用户数的方法,每天更新从当天到30天前的数据。
2708

被折叠的 条评论
为什么被折叠?



