我有三张桌子
- glSalesJournal
- HMIS添加
- HMISMain
现在我要做的是添加 glSalesJournal amt 与 HMISAdd amt 同时与各种字段分组并将结果插入 glSalesJournal
glSalesJournal 包含 633173 条记录
HMISAdd 包含 4193 条记录
HMISAdd 和 glSalesJournal 包含相同的列,它们是
- 位置
- glAcct
- glSubAcct
- 批次Nbr
- 合同Nbr
- 上午
我在表中添加了索引,结果仍然相同。
这是我的代码:
INSERT INTO hmismain
(loc,
glacct,
subacct,
batchnbr,
contractnbr,
amt)
SELECT glsalesjournal.loc,
glsalesjournal.glacct,
glsalesjournal.glsubacct,
( glsalesjournal.amt + hmisadd.amt ) AS sumAmt,
glsalesjournal.batchnbr,
glsalesjournal.salescontnbr
FROM glsalesjournal
LEFT OUTER JOIN hmisadd
ON ( glsalesjournal.loc = hmisadd.loc
AND glsalesjournal.glacct = hmisadd.glacct
AND glsalesjournal.glsubacct = hmisadd.subacct
AND glsalesjournal.batchnbr = hmisadd.batchnbr
AND glsalesjournal.salescontnbr = hmisadd.contractnbr )
GROUP BY glsalesjournal.loc,
hmisadd.loc,
glsalesjournal.glacct,
hmisadd.glacct,
glsalesjournal.glsubacct,
hmisadd.subacct,
glsalesjournal.batchnbr,
hmisadd.batchnbr,
glsalesjournal.salescontnbr,
hmisadd.contractnbr
脚本执行时间超过2小时。即使我将记录限制为 100 条,所花费的时间也是一样的。
有人可以指导我如何优化脚本。
谢谢