56,677
社区成员
发帖
与我相关
我的任务
分享
CREATE PROCEDURE pk10_Chance()
BEGIN
DECLARE _flag varchar(50);DECLARE _num1 INT;DECLARE _num2 INT;DECLARE _num3 INT;
DECLARE _num4 INT; DECLARE _num5 INT; DECLARE _num6 INT;DECLARE _num7 INT;
DECLARE _num8 INT; DECLARE _num9 INT;DECLARE _num10 INT;DECLARE _num11 INT;DECLARE _num12 VARCHAR(50);
DECLARE _num13 INT;DECLARE _num14 INT;DECLARE _num15 INT;
DECLARE _cur_finish boolean DEFAULT false;
DECLARE tempCursor CURSOR
FOR
select
'第1名大小统计' as flag,
sum(case when num=1 then 1 else 0 end) as sum1,
sum(case when num=2 then 1 else 0 end) as sum2,
sum(case when num=3 then 1 else 0 end) as sum3,
sum(case when num=4 then 1 else 0 end) as sum4,
sum(case when num=5 then 1 else 0 end) as sum5,
sum(case when num=6 then 1 else 0 end) as sum6,
sum(case when num=7 then 1 else 0 end) as sum7,
sum(case when num=8 then 1 else 0 end) as sum8,
sum(case when num=9 then 1 else 0 end) as sum9,
sum(case when num=10 then 1 else 0 end) as sum10,
sum(case when num=11 then 1 else 0 end) as sum11,
sum(case when num=12 then 1 else 0 end) as sum12,
sum(case when num=13 then 1 else 0 end) as sum13,
sum(case when num=14 then 1 else 0 end) as sum14,
sum(case when num=15 then 1 else 0 end) as sum15 from
(select case when num1 = num2 then @rownum:=@rownum+1 else @rownum:=1 end as num
from (select num1,num,(select case when num1>5 then 1 else 0 end
from pk10 where issuenum = t.num-1) as num2
from (
select case when num1>5 then 1 else 0 end as num1,issuenum as num from pk10
order by issue DESC limit 10000 ) t
)t2)t3,(select @rownum:=1) _x
;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _cur_finish = true;
OPEN tempCursor;
_cur1_loop: LOOP
FETCH NEXT FROM tempCursor INTO _flag,_num1,_num2,_num3,_num4,_num5,_num6,_num7,
_num8,_num9,_num10,_num11,_num12,_num13,_num14,_num15;
IF _cur_finish THEN LEAVE _cur1_loop; END IF;
insert into pk10_C (flag,num1,num2,num3,num4,num5,num6,num7,num8,num9,num10
,num11,num12,num13,num14,num15
) values (_flag,_num1/10000,_num2/_num1,_num3/_num2,_num4/_num3,_num5/_num4,_num6/_num5,
_num7/_num6,_num8/_num7,_num9/_num8,_num10/_num9,_num11/_num10,_num12/_num11,_num13/_num12,
_num14/_num13,_num15/_num14);
END LOOP;
CLOSE tempCursor;
END