ACCESS 2013 NOT 条件 returns 错误值

ACCESS 2013 NOT criteria returns wrong values

好的,我有这个 table

任务是获取所有没有打过狂犬病疫苗的宠物的名字

所以我做了这个查询

SELECT [Pets’ Vaccine Schedule].[Pet's Name]

FROM [Pets’ Vaccine Schedule], [Pet Vaccine]

WHERE ((Not ([Pets’ Vaccine Schedule].Vaccine)="Rabies"))

GROUP BY [Pets’ Vaccine Schedule].[Pet's Name];

问题是它显示一切正常,但它给出了宠物名字 'Bono' 而它不应该,因为 Bono 接种了最后一行显示的狂犬病疫苗。你能帮我查询吗,这样它就不会在结果中显示 Bono

您应该使用 <> 而不是 NOT。所以正确的查询应该是

SELECT [Pets' Vaccine Schedule].[Pet's Name]
FROM [Pets' Vaccine Schedule]
WHERE [Pets' Vaccine Schedule].Vaccine<>"Rabies"
GROUP BY [Pets' Vaccine Schedule].[Pet's Name];

您希望查询在每个名称级别上工作,但实际上它在记录级别上工作,它会正确地为您提供 Bono,因为有疫苗不是狂犬病疫苗(它是 DHPP)的记录。您需要编写更复杂的查询:SELECT t1.petName FROM schedule as t1 LEFT JOIN (SELECT * FROM schedule WHERE vaccine ="rabies") AS t2 ON t1.petname = t2.petname WHERE t2.petname IS NULL GROUP BY t1.petname