给定下表:
已安装的应用程序
MachineName | AppName | Version
-------------------------------
machine01 | App01 | 1.1
machine01 | App02 | 1.0
machine01 | App03 | 1.5
machine02 | App04 | 2.0
machine02 | App02 | 1.0
machine02 | App01 | 1.1
machine03 | App06 | 7.9.9
machine03 | App01 | 1.1
machine03 | App07 | 11.5
machine03 | App02 | 1.0
我需要选择Apps
给定的“n”台机器所共有的。它是“n”个集合之间的交集。但是,我很难提出一个体面的查询。
我知道我可以做这样的事情:
SELECT AppName, Version
FROM InstalledApps
WHERE MachineName = 'machine01'
INTERSECT
SELECT AppName, Version
FROM InstalledApps
WHERE MachineName = 'machine02'
那会给我
AppName | Version
------------------
App01 | 1.1
App02 | 1.0
但是,有没有一种方法可以做到,而无需预先知道机器的数量?就像是
SELECT......
FROM InstalledApps
WHERE MachineName IN ('machine01',...'machine99')