自己写的一个mysql存储过程

系统 1680 0
      DROP PROCEDURE IF EXISTS `p_sendGold`; 

CREATE PROCEDURE p_sendGold()  

BEGIN  DECLARE done INT DEFAULT 0;

   DECLARE id INT;

   DECLARE num INT;

   DECLARE flag INT;

	 DECLARE accessory1 INT;

   DECLARE cur1 CURSOR FOR SELECT u.user_id,sum(p.num) as sum_num FROM user_info u,pay_his p where u.user_id=p.user_id and date(sub_time) = date_sub(curdate(),interval 1 day) GROUP BY p.user_id ORDER BY sum_num DESC;

   DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;  

   OPEN cur1;

		

	 set flag = 0;



   REPEAT      

      FETCH cur1 INTO id,num;  

      

     

      if(num>=1000&&num<2000) then

      	 set accessory1 = 7081;

      

      ELSEIF(num>=2000&&num<5000) then

      	 set accessory1 = 7082;				

      

      ELSEIF(num>=5000&&num<10000) then

      	 set accessory1 = 7083;				 

      

      ELSEIF(num>=10000&&num<20000) then

      	 set accessory1 = 7084;				

      

      ELSEIF(num>=20000&&num<50000) then

      	 set accessory1 = 7085;				

      

      ELSEIF(num>=50000&&num<100000) then

      	 set accessory1 = 7086;				

      

      ELSEIF(num>=100000) then

      	 set accessory1 = 7087; 

			ELSE

				set accessory1 = 0;

			end IF;

			

			IF(accessory1>0) then

				insert into email_info(send_user_id,get_user_id,title,content,mail_type,send_time,readed,accessory1,accessory2,accessory3,accessory4,accessory1_num,accessory2_num,accessory3_num,accessory4_num,order_code,is_del) values(0,id,'系统邮件','充值奖励',0,now(),0,accessory1,0,0,0,1,0,0,0,0,0);     

			end IF;

		#set flag =flag+1;#记录循环次数

   UNTIL done=1 END REPEAT;

		

	 

	 #SELECT flag,num,id,accessory1;



   CLOSE cur1;

#不知道为什么上面循环最好一条记录老是插入两条记录,所以这里删除一条。

	SELECT max(email_id) into id from email_info where content='充值奖励';

	delete from email_info where email_id=id ;

	

  END


    

java技术交流群57388149

自己写的一个mysql存储过程


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论