这似乎在大型数据集上花费了很长时间。将第一个和最后 3 个查询合并为 1 个会使其更快吗?有没有人对什么可以使它更快有任何意见?我很感激。
update "detail" set bal = (units * amount) where code_type = 'AB';
update "detail" set bal = (units * amount) where code_type = 'CD';
update "detail" set bal = (units * amount) where code_type = 'EF';
update "detail" set bal = (units * amount * -1) where code_type = 'GH';
update "detail" set bal = (units * amount * -1) where code_type = 'IK';
update "detail" set bal = (units * amount * -1) where code_type = 'LM';
update "detail" set bal = 0 where code_type = 'NO';
此外 -
update bill set pay =
(select round(sum(bd1.bal),2) from "detail" bd1 where
bd1.inv = bill.inv and
(bd1.code_type = 'AB' or bd1.code_type = 'CD'));
update bill set pay = 0 where pay is null;
update bill set cost =
(select round(sum(bd2.bal),2) from "detail" bd2 where
bd2.inv = bill.inv and
(not (bd2.code_type = 'AB' or bd2.code_type = 'CD')));
update bill set cost = 0 where cost is null;
update bill set balance = round(cost + pay,2);
谢谢