mysql 存储过程 循环插入_mysql存储过程循环插入

BEGIN

declare numareaId int(10);

declare currentareaId int(10);

declare typesIdx int(10);

SELECT COUNT(areaId),MIN(areaId) INTO @a,@b FROM option_area_info;

select max(idx) INTO @iTypesIdx from types;

SET typesIdx=@iTypesIdx;

SET numareaId=@a;

SET currentareaId=@b;

loop1:WHILE numareaId>0 DO

SET @AID = currentareaId;

select date_format(current_date(),'%y-%m-%d %23:%55:%00') INTO @cTime;

select current_date() INTO @curTime;

loop2:WHILE typesIdx>0 DO

select types,subType INTO @iTypes,@iSubType from types where idx=typesIdx;

insert into game_con (areaId,mainChannel,channel,types,subType,useCount,useInputCount,useUnInputCount,conGold,conGmoney,conMilitary,conPubScore,conPst,createTime) values (

currentareaId,

1000,

1000,

@iTypes,

@iSubType,

(select count(playerId) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType),

(select count(playerId) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType and vip>0),

(select count(playerId) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType and vip=0),

(select sum(ggold) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType),

(select sum(gmoney) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType),

(select sum(military) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType),

(select sum(military) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType),

(select sum(pubScore) from log_consumption where createTime>=@curTime and createTime<=@cTime and areaId=@AID and types=@iTypes and subType=@iSubType),

(NOW()));

SET typesIdx=typesIdx-1;

end WHILE loop2;

SET numareaId=numareaId-1;

SET currentareaId=currentareaId+1;

END WHILE loop1;

END

option_area_info 表里边有连个区,1区 和2区。但是我写的这个存储过程为什么直插入了1区,却不能插入2区?是因为我嵌套的问题么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值