1

我正在从我们的 SCCM 服务器分析添加/删除程序数据,需要一些查询帮助。

数据已从 SCCM 检索并清理,因此我只剩下我感兴趣的实际应用程序列表。常用应用程序/安全更新/运行时等已被过滤掉。

我需要定义一个 SQL 查询,只有当它们有一个或多个由列表定义的应用程序时,它才会给我一个计算机及其应用程序的列表。

例如

Computer    | Application
--------------------------------------
WKS001      | Microsoft Office
WKS001      | WebEx
WKS001      | Java Runtime 1.6_33
--------------------------------------
WKS002      | Microsoft Office
WKS002      | WebEx
WKS002      | Java Runtime 1.6_33
WKS002      | Photoshop
--------------------------------------
WKS003      | WebEx
WKS003      | Java Runtime 1.6_33
--------------------------------------
WKS004      | WebEx
WKS004      | Photoshop

我需要检索具有以下任何或所有应用程序的所有计算机:

Microsoft Office
WebEx
Java Runtime 1.6_33

那应该给我 WKS001WKS003

4

3 回答 3

1

如果您需要排除具有不在该列表中的应用程序的计算机:

SELECT DISTINCT t1.Computer
FROM Table AS t1
LEFT OUTER JOIN Table AS t2 ON t1.Computer = t2.Computer
    AND t2.Application NOT IN ('Microsoft Office','WebEx','Java Runtime 1.6_33')
WHERE t1.Application IN ('Microsoft Office','WebEx','Java Runtime 1.6_33')
  AND t2.Computer IS NULL;
于 2012-11-30T20:06:43.917 回答
0
SELECT Computer, Application
FROM TABLE_NAME_HERE
WHERE Application='Microsoft Office' 
   OR Application='WebEx' 
   OR Application='Java Runtime 1.6_33'
于 2012-11-30T20:08:51.313 回答
0

其他答案不会带回计算机的应用程序。试试这个:

SELECT
    computer
    ,application
FROM
    TABLENAME 
WHERE
    computer IN
        (
            SELECT
                computer
            FROM
                TABLENAME
            WHERE
                application IN
                    (
                        'Microsoft Office'
                        ,'WebEx'
                        ,'Java Runtime 1.6_33'
                    )
        )
    AND comptuer NOT IN 
        (
            SELECT
                computer
            FROM
                TABLENAME
            WHERE
                application NOT IN
                    (
                        'Microsoft Office'
                        ,'WebEx'
                        ,'Java Runtime 1.6_33'
                    )
        )
于 2012-11-30T20:08:53.890 回答