8

如何在 ms 访问中获得与下面的 SQL 代码相同的结果?它不承认该EXCEPT子句...

SELECT DISTINCT 
       P.Name, 
       T.Training
  FROM Prof AS P, 
       Training_done AS TC, 
       Trainings AS T
 WHERE (P.Name Like '*' & NameProf & '*') 
   AND (P.Primary_Area = T.Cod_Area)
EXCEPT
SELECT DISTINCT 
       P.Name, 
       T.Training
  FROM Prof AS P, 
       Training_done AS TC, 
       Trainings AS T
 WHERE (P.Name Like '*' & NameProf & '*') 
   AND (P.Cod_Prof = TC.Cod_Prof);

提前致谢!

4

4 回答 4

6

为了摆脱EXCEPT你可以结合条件并否定第二个:

SELECT DISTINCT 
       P.Name, 
       T.Training
  FROM Prof AS P, 
       Training_done AS TC, 
       Trainings AS T
 WHERE ((P.Name Like '*' & NameProf & '*') AND
        (P.Primary_Area = T.Cod_Area)) 
   AND NOT ((P.Name Like '*' & NameProf & '*') AND
            (P.Cod_Prof = TC.Cod_Prof));
于 2013-04-12T20:53:50.840 回答
4
SELECT A.x FROM A
EXCEPT
SELECT B.x FROM B

对应于

SELECT A.x FROM A 
LEFT JOIN B 
ON A.x = B.x 
WHERE B.x IS NULL
于 2014-09-02T20:51:39.530 回答
1

使用MS Access > Create > Query Wizard中的find unmatched 向导,您将得到以下结果

联合是一个单独的访问查询,我用来联合几个表而不是使用子查询

SELECT TableMain.Field1
FROM TableMain LEFT JOIN [Union] ON TableMain.[Field1] = Union.[field1]
WHERE (((Union.field1) Is Null));
于 2015-02-15T12:13:09.783 回答
0

这里不是一个明确的例子,但考虑对两个获取的表进行 UNION 并从该联合中选择具有少于 2 个特定字段组合实例的对。这意味着,如果每个表在字段组合上具有多个具有相同值的记录实例,则这些记录是相同的并且可以从结果集中消除。如果不是,它们对一个表是唯一的,只留下所选表中与另一表不匹配的记录。有点像穷人的“除了”KW。

于 2016-06-12T16:58:17.147 回答