mysql数据存储过程代码_mysql数据库存储过程

CREATE DEFINER = 'root'@'localhost'

PROCEDURE myhouse.calculate_wtht_server_fee(IN store_Id VARCHAR(255), IN startDate VARCHAR(30), IN endDate VARCHAR(30))

BEGIN

DECLARE i int DEFAULT 1;

DECLARE v_heTongBian varchar(50);

DECLARE v_wordType varchar(1);

DECLARE v_albsz varchar(1);

DECLARE v_bcChoinceTwo varchar(30);

DECLARE v_serviceMiddleMoney int DEFAULT 0;

DECLARE v_zhuanRangPriceT int DEFAULT 0;

DECLARE v_bcChoinceNote11 varchar(10);

DECLARE v_jdr varchar(10);

DECLARE temp_count int;

declare tmp_sum int default 0;

DECLARE lp_flag boolean DEFAULT TRUE;

DECLARE wtht_cursor CURSOR FOR SELECT heTongBian,wordType,albsz,bcChoinceTwo,serviceMiddleMoney,zhuanRangPriceT,bcChoinceNote11,jdr FROM wtht WHERE jdr in (select xm from sys_yh where find_in_set(StoreID, store_Id) and (isDel <> -1 or isDel is null)) AND creatTime >= startDate AND creatTime < endDate and wordType<>6 and wordType<>5 and (flag=3 or flag=-3) order by heTongBian,wordType desc;

-- handler 句柄

DECLARE continue handler for NOT FOUND set lp_flag = false;

drop table if exists temp_wtht_fee;

-- 创建临时表收集数据

CREATE temporary TABLE `temp_wtht_fee` (

`agentName` varchar(20) COMMENT '经纪人姓名',

`secondContractTotal` int COMMENT '二手买卖签单业绩',

`secondSignNum` int COMMENT '签单数量'

) ENGINE=InnoDB;

OPEN wtht_cursor;

WHILE lp_flag DO

fetch wtht_cursor into v_heTongBian,v_wordType,v_albsz,v_bcChoinceTwo,v_serviceMiddleMoney,v_zhuanRangPriceT,v_bcChoinceNote11,v_jdr;

SELECT COUNT(*) INTO temp_count FROM temp_wtht_fee WHERE agentName=v_jdr;

IF temp_count=0 THEN

INSERT INTO temp_wtht_fee VALUES (v_jdr,0,0);

end if;

IF i%3<>0 THEN

SET i = i + 1;

if v_wordType = 4 then

if v_bcChoinceTwo like '%⑨%' then

set tmp_sum = tmp_sum + 3000;

end if;

if v_albsz = 3 then

if v_bcChoinceTwo like '%⑧%' then

set tmp_sum = tmp_sum + v_zhuanRangPriceT*0.005;

fetch wtht_cursor into v_heTongBian,v_wordType,v_albsz,v_bcChoinceTwo,v_serviceMiddleMoney,v_zhuanRangPriceT,v_bcChoinceNote11,v_jdr;

set i = i + 1;

set tmp_sum = tmp_sum + v_serviceMiddleMoney;

elseif v_bcChoinceTwo like '%⑪%' then

set tmp_sum = tmp_sum + v_bcChoinceNote11;

fetch wtht_cursor into v_heTongBian,v_wordType,v_albsz,v_bcChoinceTwo,v_serviceMiddleMoney,v_zhuanRangPriceT,v_bcChoinceNote11,v_jdr;

set i = i + 1;

set tmp_sum = tmp_sum + v_serviceMiddleMoney;

else

fetch wtht_cursor into v_heTongBian,v_wordType,v_albsz,v_bcChoinceTwo,v_serviceMiddleMoney,v_zhuanRangPriceT,v_bcChoinceNote11,v_jdr;

set i = i + 1;

set tmp_sum = tmp_sum + v_serviceMiddleMoney;

end if;

else

fetch wtht_cursor into v_heTongBian,v_wordType,v_albsz,v_bcChoinceTwo,v_serviceMiddleMoney,v_zhuanRangPriceT,v_bcChoinceNote11,v_jdr;

set i = i + 1;

set tmp_sum = tmp_sum + v_serviceMiddleMoney;

end if;

elseif v_wordType = 1 then

set tmp_sum = tmp_sum + v_serviceMiddleMoney;

end if;

ELSE

SET i = 1;

set tmp_sum = tmp_sum + v_serviceMiddleMoney;

UPDATE temp_wtht_fee set secondSignNum=secondSignNum+1,secondContractTotal=secondContractTotal+tmp_sum WHERE agentName=v_jdr;

set tmp_sum = 0;

END IF;

END WHILE;

CLOSE wtht_cursor;

END

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值