<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        Mysql存儲過程計算留存率

        來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-09 12:56:45
        文檔

        Mysql存儲過程計算留存率

        Mysql存儲過程計算留存率:涉及了 循環(huán)、參數(shù)定義、游標(biāo)的使用。 最終代碼 ============不區(qū)分org的總數(shù)據(jù)===DELIMITER $$DROP PROCEDURE IF EXISTS weekly_remain $$#IN參數(shù)類型,傳進(jìn)的參數(shù)CREATE PROCEDURE weekly_remain(IN lobby int) B
        推薦度:
        導(dǎo)讀Mysql存儲過程計算留存率:涉及了 循環(huán)、參數(shù)定義、游標(biāo)的使用。 最終代碼 ============不區(qū)分org的總數(shù)據(jù)===DELIMITER $$DROP PROCEDURE IF EXISTS weekly_remain $$#IN參數(shù)類型,傳進(jìn)的參數(shù)CREATE PROCEDURE weekly_remain(IN lobby int) B

        涉及了 循環(huán)、參數(shù)定義、游標(biāo)的使用。 最終代碼 ============不區(qū)分org的總數(shù)據(jù)===DELIMITER $$DROP PROCEDURE IF EXISTS weekly_remain $$#IN參數(shù)類型,傳進(jìn)的參數(shù)CREATE PROCEDURE weekly_remain(IN lobby int) BEGIN #定義參數(shù)declare i int(2);declare e

        涉及了 循環(huán)、參數(shù)定義、游標(biāo)的使用。

        最終代碼

        ============不區(qū)分org的總數(shù)據(jù)===
        DELIMITER $$
        DROP PROCEDURE IF EXISTS weekly_remain $$
        #IN參數(shù)類型,傳進(jìn)的參數(shù)
        CREATE PROCEDURE weekly_remain(IN lobby int) 
        BEGIN 
        #定義參數(shù)
        declare i int(2);
        declare ext_table varchar(20);
        declare uniq_no int(10);
        declare now_week varchar(20);
        declare c2 varchar(10);
        declare c3 varchar(10);
        declare c4 varchar(10);
        declare c5 varchar(10);
        declare c6 varchar(10);
        SET now_week = date_format(date_sub(curdate(),interval 1 week),"%Y-%u");
        SET i = 1;
        if (lobby=101) or (lobby=102) or (lobby=104) or(lobby=105) or (lobby=107) or (lobby=108) then
        #引入?yún)?shù)@c,局部變量
        	select count(distinct(stbid)) INTO @c from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week and gate_uri=lobby;
        	SET uniq_no= @c;
        	insert into gp_weekly_leave(uniq_login,week,lobby_id) select count(distinct(stbid)),date_format(login_time,"%Y-%u"),gate_uri from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week and gate_uri=lobby;
        	select count(distinct(t1.stb)) INTO @c_2 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 2 week),"%Y-%u") and gate_uri=lobby) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week and gate_uri=lobby) as t2 where t1.stb=t2.stb;
        	SET c2=@c_2/uniq_no;
        	update gp_weekly_leave set two_week=c2 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_3 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 3 week),"%Y-%u") and gate_uri=lobby) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week and gate_uri=lobby) as t2 where t1.stb=t2.stb;
        	SET c3=@c_3/uniq_no;
        	update gp_weekly_leave set three_week=c3 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_4 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 4 week),"%Y-%u") and gate_uri=lobby) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week and gate_uri=lobby) as t2 where t1.stb=t2.stb;
        	SET c4=@c_4/uniq_no;
        	update gp_weekly_leave set four_week=c4 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_5 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 5 week),"%Y-%u") and gate_uri=lobby) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week and gate_uri=lobby) as t2 where t1.stb=t2.stb;
        	SET c5=@c_5/uniq_no;
        	update gp_weekly_leave set five_week=c5 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_6 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 6 week),"%Y-%u") and gate_uri=lobby) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week and gate_uri=lobby) as t2 where t1.stb=t2.stb;
        	SET c6=@c_6/uniq_no;
        	update gp_weekly_leave set six_week=c6 where week=now_week and lobby_id=lobby;
        end if;
        if (lobby=1000) then
        	select count(distinct(stbid)) INTO @c from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week;
        	SET uniq_no= @c;
        	insert into gp_weekly_leave(uniq_login,week,lobby_id) select count(distinct(stbid)),date_format(login_time,"%Y-%u"),'1000' from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week;
        	select count(distinct(t1.stb)) INTO @c_2 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 2 week),"%Y-%u")) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week) as t2 where t1.stb=t2.stb;
        	SET c2=@c_2/uniq_no;
        	update gp_weekly_leave set two_week=c2 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_3 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 3 week),"%Y-%u")) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week) as t2 where t1.stb=t2.stb;
        	SET c3=@c_3/uniq_no;
        	update gp_weekly_leave set three_week=c3 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_4 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 4 week),"%Y-%u")) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week) as t2 where t1.stb=t2.stb;
        	SET c4=@c_4/uniq_no;
        	update gp_weekly_leave set four_week=c4 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_5 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 5 week),"%Y-%u")) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week) as t2 where t1.stb=t2.stb;
        	SET c5=@c_5/uniq_no;
        	update gp_weekly_leave set five_week=c5 where week=now_week and lobby_id=lobby;
        	select count(distinct(t1.stb)) INTO @c_6 from (select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 6 week),"%Y-%u")) as t1,(select distinct(stbid) as stb from gp_gate_login_recent where date_format(login_time,"%Y-%u")=now_week) as t2 where t1.stb=t2.stb;
        	SET c6=@c_6/uniq_no;
        	update gp_weekly_leave set six_week=c6 where week=now_week and lobby_id=lobby;
        end if;
        END
        $$
        DELIMITER ;
        --#====拓展--存儲過程--區(qū)分orgid===#--
        DELIMITER $$
        DROP PROCEDURE IF EXISTS weekly_remain_tz $$
        CREATE PROCEDURE weekly_remain_tz() 
        BEGIN 
        #默認(rèn)值
        declare lobby int(5) default 104;
        declare i int(2);
        declare ext_table varchar(20);
        declare uniq_no int(10);
        declare now_week varchar(20);
        declare c2 varchar(10);
        declare c3 varchar(10);
        declare c4 varchar(10);
        declare c5 varchar(10);
        declare c6 varchar(10);
        declare a int(10);
        declare b varchar(20);
        declare leave2 varchar(20);
        declare leave3 varchar(20);
        declare leave4 varchar(20);
        declare leave5 varchar(20);
        DECLARE leave6 varchar(20);
        DECLARE percent2 varchar(20);
        DECLARE percent3 varchar(20);
        DECLARE percent4 varchar(20);
        DECLARE percent5 varchar(20);
        DECLARE percent6 varchar(20);
        #游標(biāo)定義與開始
        DECLARE s int default 0;
        #定義游標(biāo)
        DECLARE cursor_name CURSOR FOR select t4.vc_org_id,count(distinct(t3.stbid)) from gp_gate_login_recent t3,tv_gp_ext_tzwasu t4 where date_format(t3.login_time,"%Y-%u")=now_week and t3.stbid=t4.vc_stb_id and t3.gate_uri=lobby group by t4.vc_org_id;
        #設(shè)置
        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s=1;
        SET now_week = date_format(date_sub(curdate(),interval 1 week),"%Y-%u");
        SET i = 1;
        #先插入數(shù)據(jù)
        insert into gp_weekly_leave(uniq_login,week,lobby_id,orgid) select count(distinct(ta.stbid)),date_format(ta.login_time,"%Y-%u"),ta.gate_uri,tb.vc_org_id from gp_gate_login_recent ta,tv_gp_ext_tzwasu tb where date_format(ta.login_time,"%Y-%u")=now_week and ta.gate_uri=lobby and ta.stbid=tb.vc_stb_id group by tb.vc_org_id;
        #開啟游標(biāo)
        OPEN cursor_name;
        #對每一行的數(shù)據(jù)進(jìn)行輪訓(xùn)
        fetch cursor_name into a,b;
        while s 
         1 do 
        #進(jìn)行2周、3周、4周、5周、6周留存的計算
        	select count(distinct(t3.stb)) INTO @leave2 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 2 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent2=leave2/b;
        	update gp_weekly_leave set two_week=percent2 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave3 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 3 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent3=leave3/b;
        	update gp_weekly_leave set three_week=percent3 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave4 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 4 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent4=leave4/b;
        	update gp_weekly_leave set four_week=percent4 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave5 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 5 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent5=leave5/b;
        	update gp_weekly_leave set five_week=percent5 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave6 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 6 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_tzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent6=leave6/b;
        	update gp_weekly_leave set six_week=percent6 where orgid=a and lobby_id=lobby and week=now_week; 
        	fetch cursor_name into a,b; 
        end while; 
        #關(guān)閉游標(biāo)
        CLOSE cursor_name ;
        END
        $$
        DELIMITER ;
        --#====杭州--存儲過程--區(qū)分orgid===#--
        DELIMITER $$
        DROP PROCEDURE IF EXISTS weekly_remain_hz $$
        CREATE PROCEDURE weekly_remain_hz() 
        BEGIN 
        declare lobby int(5) default 101;
        declare i int(2);
        declare ext_table varchar(20);
        declare uniq_no int(10);
        declare now_week varchar(20);
        declare c2 varchar(10);
        declare c3 varchar(10);
        declare c4 varchar(10);
        declare c5 varchar(10);
        declare c6 varchar(10);
        declare a int(10);
        declare b varchar(20);
        declare leave2 varchar(20);
        declare leave3 varchar(20);
        declare leave4 varchar(20);
        declare leave5 varchar(20);
        DECLARE leave6 varchar(20);
        DECLARE percent2 varchar(20);
        DECLARE percent3 varchar(20);
        DECLARE percent4 varchar(20);
        DECLARE percent5 varchar(20);
        DECLARE percent6 varchar(20);
        DECLARE s int default 0;
        DECLARE cursor_name CURSOR FOR select t4.vc_org_id,count(distinct(t3.stbid)) from gp_gate_login_recent t3,tv_gp_ext_hzwasu t4 where date_format(t3.login_time,"%Y-%u")=now_week and t3.stbid=t4.vc_stb_id and t3.gate_uri=lobby group by t4.vc_org_id;
        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s=1;
        SET now_week = date_format(date_sub(curdate(),interval 1 week),"%Y-%u");
        SET i = 1;
        insert into gp_weekly_leave(uniq_login,week,lobby_id,orgid) select count(distinct(ta.stbid)),date_format(ta.login_time,"%Y-%u"),ta.gate_uri,tb.vc_org_id from gp_gate_login_recent ta,tv_gp_ext_hzwasu tb where date_format(ta.login_time,"%Y-%u")=now_week and ta.gate_uri=lobby and ta.stbid=tb.vc_stb_id group by tb.vc_org_id;
        OPEN cursor_name;
        fetch cursor_name into a,b;
        while s 
         1 do 
        	select count(distinct(t3.stb)) INTO @leave2 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 2 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent2=leave2/b;
        	update gp_weekly_leave set two_week=percent2 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave3 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 3 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent3=leave3/b;
        	update gp_weekly_leave set three_week=percent3 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave4 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 4 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent4=leave4/b;
        	update gp_weekly_leave set four_week=percent4 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave5 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 5 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent5=leave5/b;
        	update gp_weekly_leave set five_week=percent5 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave6 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 6 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_hzwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent6=leave6/b;
        	update gp_weekly_leave set six_week=percent6 where orgid=a and lobby_id=lobby and week=now_week; 
        	fetch cursor_name into a,b; 
        end while; 
        CLOSE cursor_name ;
        END
        $$
        DELIMITER ;
        --#====省網(wǎng)--存儲過程--區(qū)分orgid===#--
        DELIMITER $$
        DROP PROCEDURE IF EXISTS weekly_remain_sw $$
        CREATE PROCEDURE weekly_remain_sw() 
        BEGIN 
        declare lobby int(5) default 102;
        declare i int(2);
        declare ext_table varchar(20);
        declare uniq_no int(10);
        declare now_week varchar(20);
        declare c2 varchar(10);
        declare c3 varchar(10);
        declare c4 varchar(10);
        declare c5 varchar(10);
        declare c6 varchar(10);
        declare a int(10);
        declare b varchar(20);
        declare leave2 varchar(20);
        declare leave3 varchar(20);
        declare leave4 varchar(20);
        declare leave5 varchar(20);
        DECLARE leave6 varchar(20);
        DECLARE percent2 varchar(20);
        DECLARE percent3 varchar(20);
        DECLARE percent4 varchar(20);
        DECLARE percent5 varchar(20);
        DECLARE percent6 varchar(20);
        DECLARE s int default 0;
        DECLARE cursor_name CURSOR FOR select t4.vc_org_id,count(distinct(t3.stbid)) from gp_gate_login_recent t3,tv_gp_ext_swwasu t4 where date_format(t3.login_time,"%Y-%u")=now_week and t3.stbid=t4.vc_stb_id and t3.gate_uri=lobby group by t4.vc_org_id;
        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s=1;
        SET now_week = date_format(date_sub(curdate(),interval 1 week),"%Y-%u");
        SET i = 1;
        insert into gp_weekly_leave(uniq_login,week,lobby_id,orgid) select count(distinct(ta.stbid)),date_format(ta.login_time,"%Y-%u"),ta.gate_uri,tb.vc_org_id from gp_gate_login_recent ta,tv_gp_ext_swwasu tb where date_format(ta.login_time,"%Y-%u")=now_week and ta.gate_uri=lobby and ta.stbid=tb.vc_stb_id group by tb.vc_org_id;
        OPEN cursor_name;
        fetch cursor_name into a,b;
        while s 
         1 do 
        	select count(distinct(t3.stb)) INTO @leave2 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 2 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent2=leave2/b;
        	update gp_weekly_leave set two_week=percent2 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave3 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 3 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent3=leave3/b;
        	update gp_weekly_leave set three_week=percent3 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave4 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 4 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent4=leave4/b;
        	update gp_weekly_leave set four_week=percent4 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave5 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 5 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent5=leave5/b;
        	update gp_weekly_leave set five_week=percent5 where orgid=a and lobby_id=lobby and week=now_week;
        	select count(distinct(t3.stb)) INTO @leave6 from (select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=date_format(date_sub(curdate(),interval 6 week),"%Y-%u")) as t3,(select distinct(t1.stbid) as stb from gp_gate_login_recent t1,tv_gp_ext_swwasu t2 where t1.gate_uri=lobby and t1.stbid=t2.vc_stb_id and t2.vc_org_id=a and date_format(t1.login_time,"%Y-%u")=now_week) as t4 where t3.stb=t4.stb;
        	SET percent6=leave6/b;
        	update gp_weekly_leave set six_week=percent6 where orgid=a and lobby_id=lobby and week=now_week; 
        	fetch cursor_name into a,b; 
        end while; 
        CLOSE cursor_name ;
        END
        $$
        DELIMITER ;
        ===========TIPS===
        ---執(zhí)行方法,不區(qū)分org 則調(diào)用weekly_remain(lobbyid) 101 102 104 105 107 108:
        CALL weekly_remain(1000);
        ---區(qū)分orgid 調(diào)用:
        CALL weekly_remain_hz();
        CALL weekly_remain_sw();
        CALL weekly_remain_tz();
        

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Mysql存儲過程計算留存率

        Mysql存儲過程計算留存率:涉及了 循環(huán)、參數(shù)定義、游標(biāo)的使用。 最終代碼 ============不區(qū)分org的總數(shù)據(jù)===DELIMITER $$DROP PROCEDURE IF EXISTS weekly_remain $$#IN參數(shù)類型,傳進(jìn)的參數(shù)CREATE PROCEDURE weekly_remain(IN lobby int) B
        推薦度:
        標(biāo)簽: 過程 定義 計算
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲国产aⅴ综合网| 免费看一级做a爰片久久| 亚洲精品成人片在线播放 | 亚洲精品无码MV在线观看| 一级特黄录像免费播放肥| 日韩亚洲变态另类中文| 国产成人无码区免费内射一片色欲| 在线亚洲人成电影网站色www| 精品国产污污免费网站入口在线 | 亚洲精品无码国产片| 国产免费观看网站| 男女啪啪免费体验区| 亚洲精品午夜无码专区| 特级无码毛片免费视频尤物| 成人a毛片视频免费看| 亚洲精品人成无码中文毛片| 一级有奶水毛片免费看| 亚洲邪恶天堂影院在线观看| 永久免费毛片在线播放| 亚洲AV无码AV吞精久久| 在线精品亚洲一区二区三区| 免费播放一区二区三区| 亚洲字幕AV一区二区三区四区 | 在线日韩av永久免费观看| 无码毛片一区二区三区视频免费播放 | 拍拍拍无挡免费视频网站| 亚洲福利视频一区二区三区| 成年女人看片免费视频播放器| 理论秋霞在线看免费| 久久夜色精品国产嚕嚕亚洲av| 97性无码区免费| 三年片在线观看免费观看大全中国| 亚洲国产成人久久综合一| 免费看的一级毛片| 十八禁在线观看视频播放免费| 亚洲图片激情小说| 国产精品亚洲视频| 成年免费a级毛片| 337p日本欧洲亚洲大胆色噜噜| 日本一道一区二区免费看| 色www永久免费|