我编写了一个查询,旨在返回用户之间的事务分钟数。 MS Access需要10分钟才能运行它,我无法使用结果。如何改善其表现?
SELECT TestDataset.ID, TestDataset.OperatorID, TestDataset.DTCreated,
(SELECT TOP 1 t2.DtCreated
FROM TestDataSet as t2
WHERE t2.OperatorID = TestDataset.OperatorID AND t2.DtCreated < TestDataset.DtCreated
ORDER BY t2.DtCreated,t2.ID
) as PreviousTransaction,
Minute([DtCreated]-[PreviousTransaction]) AS Minutes
FROM TestDataset
ORDER BY TestDataset.OperatorID, TestDataset.DTCreated;
答案 0 :(得分:2)
您可以考虑将数据库切换为更强大的功能。大多数数据库都支持ANSI标准窗口函数,它们可以直接执行您想要的操作。
但是,对于您的情况,首先尝试TestDataset(OperatorID, DtCreated, Id)
上的索引:
create index idx_TestDataset_OperatorID_DtCreated_Id on TestDataset(OperatorID, DtCreated, Id);