mysql 无参存储过程

DROP PROCEDURE IF EXISTS `Sum_Month_Cus_Count`;

CREATE PROCEDURE `Sum_Month_Cus_Count`()
BEGIN
declare v_cur_Date date;
declare v_pre1_Date date;
declare v_year,v_month,v_count int;
set v_cur_Date = CURDATE();
set v_pre1_Date = date_add(v_cur_Date, interval -1 day) ;
set v_year =year(v_pre1_Date);
set v_month = month(v_pre1_Date);
select count(syear) into v_count from rpl_month_cycle where syear =v_year and smonth=v_month;
if v_count=0 THEN
INSERT into rpl_month_cycle(syear,smonth) values(v_year,v_month);
end if;
delete from rpl_cus_month_sum where syear =v_year and smonth=v_month;

select v_year,v_month ,ta.groupId,IFNULL(tb.addNum,0),0
from cus_group as ta
left join
(
select egroupId,count(egroupId) as addNum from cus_costomer_up_history where year(changeDate) = v_year and month(changeDate)=v_month group by egroupId
) as tb
on ta.groupId = tb.egroupId
where ta.IsSum =1;

insert into rpl_cus_month_sum
select v_year,v_month ,ta.groupId,IFNULL(tb.addNum,0),0
from cus_group as ta
left join
(
select egroupId,count(egroupId) as addNum from cus_costomer_up_history where year(changeDate) = v_year and month(changeDate)=v_month group by egroupId
) as tb
on ta.groupId = tb.egroupId
where ta.IsSum =1;

update rpl_cus_month_sum as ta,
(
select groupId,count(groupId) as totalNum from cus_customer where State=1 group by groupId
) as tb
set ta.totalNum = tb.totalNum
where ta.groupId = tb.groupId
and ta.syear = v_year
and ta.smonth=v_month;
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值