0

我有以下查询

SELECT DISTINCT T_Med.Comp, T_Med.ItemID, T_Med.WP, T_Med.DocName, T_Med.TrfCode, 
       T_Med.CatDescr, T_Med.SubCatDescr, T_LKPWP.RuleCode, T_MedWP.RuleCode, 
       T_Med.Group
FROM (T_Med INNER JOIN T_LKPWP ON (T_Med.DocName=T_LKPWP.SDocName)
AND (T_Med.[WP]=T_LKPWP.WP)) 
LEFT JOIN T_MedWP ON T_LKPWP.RuleCode=T_MedWP.RuleCode
WHERE (((T_MedWP.RuleCode) Is Null));

由于 DISTINCT 需要很长时间来处理。正如我发现的那样,即使我为这些相关字段创建了索引,它也无助于 DISTINCT。没有 DISTINCT 相同的查询给出的结果不到一秒

这里T_Med有1070065条记录,T_MedWP有366315条记录,T_LKPWP有55条记录

反正有没有以不同的方式实现预期的结果。我试图创建一个没有 DISTINCT 的单独表,即使这需要很长时间。

感谢您的评论

4

2 回答 2

0
 SELECT DISTINCT Comp, ItemID, WP, DocName, TrfCode, 
   CatDescr, SubCatDescr, RuleCode, .RuleCode, 
   Group FROM (

 maybe try this...

 SELECT T_Med.Comp, T_Med.ItemID, T_Med.WP, T_Med.DocName, T_Med.TrfCode, 
   T_Med.CatDescr, T_Med.SubCatDescr, T_LKPWP.RuleCode, T_MedWP.RuleCode, 
   T_Med.Group
  FROM (T_Med INNER JOIN T_LKPWP ON (T_Med.DocName=T_LKPWP.SDocName)
   AND (T_Med.[WP]=T_LKPWP.WP)) 
   LEFT JOIN T_MedWP ON T_LKPWP.RuleCode=T_MedWP.RuleCode
   WHERE (((T_MedWP.RuleCode) Is Null));

  )

还使用 DISTINCT 检查这个 需要很长时间的查询

于 2013-02-14T19:19:47.293 回答
0

这是一般的 Oracle 示例,但也许它会给您一些想法。我对Access不太了解,抱歉。无法确定在 Access 中是否存在可用的运算符。

-- Same as Distinct --
SELECT deptno, dname FROM scott.dept D WHERE EXISTS ( SELECT 'X' FROM scott.emp E WHERE E.deptno = D.deptno)
/
于 2013-02-14T19:26:59.120 回答