这是我的访问查询。我返回的每个值都是必需的(不幸的是)。然而,这个查询最糟糕的部分。是它有时会错过符合 WHERE 子句中条件的行。我尝试进行的每项优化都无济于事,或者无法在 Access 中完成(了解 SQL)。如您所见,WHERE 子句在三个日期字段之间进行检查。这是棘手的部分。对于 Inventory Masterfile 中的每一行信息,Inventory Stores 中有五行(每个“BranchID”一个),并且我在 where 子句中检查的日期列可以在这五个中的任何一个中更新日期行,到 Inventory Masterfile 中的一行。有没有人有任何可以帮助我的建议?我已经调试了好几个星期,对此我束手无策。
SELECT a.Item1,im.Secondary,im.Description,im.Author_Artist,im.RetailPrice,im.CatalogID,im.Publisher, im.Binding,im.PubDate,im.Grouping,im.CategoryId,im.Alt_Category,
(SELECT MAX(ls.OnHand) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 5)) AS 1Stock,
(SELECT MAX(ls.OnHand) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 3)) AS 2Stock,
(SELECT MAX(ls.OnHand) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 4)) AS 3Stock,
(SELECT MAX(ls.Maximum) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 4)) AS Maximum,
(SELECT MAX(ls.LastSold1) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1)) AS LastSold1,
(SELECT MAX(ls.LastUpdate) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1)) AS LastUpdate,
(SELECT MAX(ls.LastReceived) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1)) AS LastReceived
FROM [Inventory Store] AS a
INNER JOIN [Inventory Masterfile] im ON a.Item1 = im.Item1
WHERE (a.LastSold1 > #6/12/2012# OR a.LastUpdate > #6/12/2012# OR a.LastReceived > #6/12/2012#)
GROUP BY a.Item1, im.Secondary, im.Description, im.Author_Artist, im.RetailPrice,
im.CatalogID,im.Publisher, im.Binding,im.PubDate,im.Grouping,im.CategoryId,im.Alt_Category