我没有创建这个数据库,所以我对它的构建方式的知识非常有限,但是我被要求编写一个查询来获取一些信息。我需要找到所有没有安装Microsoft .NET Framework 4 Client Profile的设备。自从上次我写了一些SQL以来,已经有一段时间了,所以原谅我所做的任何新手语法错误。
我有以下表格:
devices
software
software_installations
我认为关系使用以下字段:
software_installations有一个computer_id和software_id
软件有一个id
设备有ID
我能够通过以下查询查询所有安装了软件的设备:
SELECT devices.name, software.name
FROM software_installations
INNER JOIN devices ON devices.id = software_installations.computer_id
INNER JOIN software ON software.id = software_installations.software_id
WHERE devices.dn LIKE "%OU=POLICE_OU%" AND software.name = "Microsoft .NET Framework 4 Client Profile";
现在我需要的信息,不是那些人的信息。我最初的想法是做出以下改变,
SELECT devices.name, software.name
FROM software_installations
INNER JOIN devices ON devices.id = software_installations.computer_id
INNER JOIN software ON software.id = software_installations.software_id
WHERE devices.dn LIKE "%OU=POLICE_OU%" AND software.name != "Microsoft .NET Framework 4 Client Profile";
但在执行时我意识到这不是我所需要的,所以现在我很难过。
答案 0 :(得分:1)
尝试EXCEPT运算符: -
SELECT devices.name
FROM devices
EXCEPT
SELECT devices.name
FROM software_installations
INNER JOIN devices ON devices.id = software_installations.computer_id
INNER JOIN software ON software.id = software_installations.software_id
WHERE devices.dn LIKE "%OU=POLICE_OU%" AND software.name = "Microsoft .NET Framework 4 Client Profile";