Maison base de données tutoriel mysql Mysql存储过程计算留存率

Mysql存储过程计算留存率

Jun 07, 2016 pm 04:41 PM
mysql 参数 存储 定义 循环 留存率 计算 processus

涉及了 循环、参数定义、游标的使用。 最终代码 ============不区分org的总数据===DELIMITER $$DROP PROCEDURE IF EXISTS weekly_remain $$#IN参数类型,传进的参数CREATE PROCEDURE weekly_remain(IN lobby int) BEGIN #定义参数declare i int(2);declare e

涉及了 循环、参数定义、游标的使用。

最终代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

============不区分org的总数据===

DELIMITER $$

DROP PROCEDURE IF EXISTS weekly_remain $$

#IN参数类型,传进的参数

CREATE PROCEDURE weekly_remain(IN lobby int) 

BEGIN 

#定义参数

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

#引入参数@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 ;

--#====拓展--存储过程--区分orgid===#--

DELIMITER $$

DROP PROCEDURE IF EXISTS weekly_remain_tz $$

CREATE PROCEDURE weekly_remain_tz() 

BEGIN 

#默认值

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);

#游标定义与开始

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_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;

#设置

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_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;

#开启游标

OPEN cursor_name;

#对每一行的数据进行轮训

fetch  cursor_name into a,b;

while s <pre class="brush:php;toolbar:false"> 1 do 

#进行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;  

#关闭游标

CLOSE cursor_name ;

END

$$

DELIMITER ;

--#====杭州--存储过程--区分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 <pre class="brush:php;toolbar:false"> 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 ;

--#====省网--存储过程--区分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 <pre class="brush:php;toolbar:false"> 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===

---执行方法,不区分org 则调用weekly_remain(lobbyid)  101 102 104 105 107 108:

CALL weekly_remain(1000);

---区分orgid 调用:

CALL weekly_remain_hz();

CALL weekly_remain_sw();

CALL weekly_remain_tz();

Copier après la connexion
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Article chaud

Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD

Article chaud

Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD

Tags d'article chaud

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Compétences de traitement de structures de données volumineuses de PHP Compétences de traitement de structures de données volumineuses de PHP May 08, 2024 am 10:24 AM

Compétences de traitement de structures de données volumineuses de PHP

Comment optimiser les performances des requêtes MySQL en PHP ? Comment optimiser les performances des requêtes MySQL en PHP ? Jun 03, 2024 pm 08:11 PM

Comment optimiser les performances des requêtes MySQL en PHP ?

Comment utiliser la sauvegarde et la restauration MySQL en PHP ? Comment utiliser la sauvegarde et la restauration MySQL en PHP ? Jun 03, 2024 pm 12:19 PM

Comment utiliser la sauvegarde et la restauration MySQL en PHP ?

Comment insérer des données dans une table MySQL en utilisant PHP ? Comment insérer des données dans une table MySQL en utilisant PHP ? Jun 02, 2024 pm 02:26 PM

Comment insérer des données dans une table MySQL en utilisant PHP ?

Quels sont les scénarios d'application des types d'énumération Java dans les bases de données ? Quels sont les scénarios d'application des types d'énumération Java dans les bases de données ? May 05, 2024 am 09:06 AM

Quels sont les scénarios d'application des types d'énumération Java dans les bases de données ?

Comment corriger les erreurs mysql_native_password non chargé sur MySQL 8.4 Comment corriger les erreurs mysql_native_password non chargé sur MySQL 8.4 Dec 09, 2024 am 11:42 AM

Comment corriger les erreurs mysql_native_password non chargé sur MySQL 8.4

Comment utiliser les procédures stockées MySQL en PHP ? Comment utiliser les procédures stockées MySQL en PHP ? Jun 02, 2024 pm 02:13 PM

Comment utiliser les procédures stockées MySQL en PHP ?

Comment créer une table MySQL en utilisant PHP ? Comment créer une table MySQL en utilisant PHP ? Jun 04, 2024 pm 01:57 PM

Comment créer une table MySQL en utilisant PHP ?

See all articles