我运行了一些代码来对列中的旧记录进行编号,以便在数据表子表单中对项目进行排序,但是在打开依赖它的主表单时更新了库存交易表中的列之后。它运行一个查询来确定到期的客户余额,并且该查询需要永远运行 2-3 分钟或更长时间,但是恢复到它运行良好的数据的旧副本,我所做的只是重新编号一列中的记录最其中有 1s 是重新编号记录的代码:
Dim rst As DAO.Recordset
Dim i As Long
Dim OID As Long
Dim stringSQL as String
i = 1
stringSQL = "SELECT * FROM [Inventory Transactions] " _
& "WHERE [OrderID] > 0 Order By [OrderID],[TransactionID]"
Set rst = CurrentDb.OpenRecordset(stringSQL, dbOpenDynaset)
With rst
OID = rst!OrderID
Do Until .EOF
If OID = rst!OrderID Then
.Edit
!OrderLineNumber = i
.Update
.MoveNext
i = i + 1
Else
OID = rst!OrderID
i = 1
End If
Loop
.Close
End With
Set rst = Nothing
编辑1:
我今天继续玩这个,并且打破第二级子查询的查询实际上引用了我更改的库存交易表运行良好,但上升到子查询1的级别,它引用了子查询2和支付总和查询,但它阻塞了总和付款仅参考付款表。
编辑2:
我今天做了更多测试 Subquery2 和付款总和查询的运行速度都比我用秒表计时的速度要快,但是当它们组合起来大约需要 1:45 时,subquery1 中只有 5 列来自 subquery2 的 4 列和来自付款总和 3 的 1前 4 个是 sum,最后一个是 group by,然后来自付款总和的一个是 group by
子查询 2:
SELECT
CLng((nz([UnitsSold])*nz([UnitPrice]))*(1-nz([Discount]))*100)/100 AS [Line Total],
CLng([Line Total]*(1+nz([SalesTaxRate]))*100)/100 AS [Line Total With Tax],
[Line Total With Tax]-[Line Total] AS [Line Tax],
[Inventory Transactions].*
FROM [Inventory Transactions]
WHERE ((([Inventory Transactions].OrderID) Is Not Null));
付款总和查询:
SELECT DISTINCTROW Payments.OrderID,
Sum(Payments.PaymentAmount) AS [Total Payments]
FROM Payments
GROUP BY Payments.OrderID;
子查询 1:
SELECT
[Balance Due By Customers Subquery2].OrderID,
Sum([Balance Due By Customers Subquery2].[Line Total]) AS [SumOfLine Total],
Sum([Balance Due By Customers Subquery2].[Line Tax]) AS [SumOfLine Tax],
Sum([Balance Due By Customers Subquery2].[Line Total With Tax]) AS [SumOfLine Total With Tax],
[Sum Of Payments Query].[Total Payments]
FROM [Balance Due By Customers Subquery2]
LEFT JOIN [Sum Of Payments Query]
ON [Balance Due By Customers Subquery2].OrderID = [Sum Of Payments Query].OrderID
GROUP BY [Balance Due By Customers Subquery2].OrderID,
[Sum Of Payments Query].[Total Payments];