MySQL连表更新事件维护优化
数据库  /  管理员 发布于 3年前   390
优化前:
-- 备忘备注:超过账期宽限期未结款,变更机构状态“已冻结”;结清恢复; 合同授信过期按上一次合同账期,屏蔽临时授信 UPDATE bota_corper as a, ( SELECT bm.corperid,bm._corperid, sum(if(bm.settlestatus=0,1,0)) num, (select IFNULL(sum(remain),0) from bota_corper_credit as ct where ct.corperid = bm.corperid and ct.type=1 ) as ctremain FROM `bota_corper_bill_month` bm inner join `bota_corper` c on bm.corperid = c.id where date(date_add(CONCAT(bm.month,'-',c.expired),INTERVAL 1 MONTH)) < date(now()) group by corperid ) as b SET a.status = if(b.num > 0 && a.remain < 0,4,3), a._status = if(b.num > 0 && a.remain < 0,'已冻结','正常') WHERE a.id = b.corperid and b.ctremain > 0
优化后:拆分两步利于维护
-- 事件名称:机构状态自动冻结
UPDATE bota_corper as C,
(
SELECT DISTINCT
A.corperid
FROM
bota_corper_credit A,
bota_corper_bill_month B
WHERE
A.type = 1
AND
A.corperid = B.corperid
AND B.settlestatus = 0
AND B.presettle < CURDATE()
) as D
SET
C.status = 4,
C._status = '已冻结'
WHERE
C.id = D.corperid
-- 事件名称:机构状态自动解冻
UPDATE bota_corper as C,
(
SELECT DISTINCT
A.corperid
FROM
bota_corper_credit A,
bota_corper_bill_month B
WHERE
A.type = 1
AND
A.corperid = B.corperid
AND B.settlestatus = 1
) as D
SET
C.status = 3,
C._status = '正常'
WHERE
C.id = D.corperid
阿凡达123 在
golang 怎么做热更新中评论 也可以看看这个:https://github.com/edwingeng/hot..博主 在
hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 @路过的靓仔:cdn静态资源被墙,已修复..GGGGGGGGG 在
layui框架常用输入框介绍中评论 写的很好解决问题..路过的靓仔 在
hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 剩下好多 wait 状态的..激光豆芽 在
为什么你不能安逸?国内996为什么没有国外955香?中评论 国内现在无意义的内卷太多了..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号