0

在将多列转换为多行时,如何“取消透视”此 SQL 查询?我还没有找到包含字符串数据的类似示例。

我正在使用以下查询:

SELECT MIN(DISTINCT CASE WHEN ARP.DisplayName0 = 'Adobe Reader XI (11.0.01)' AND 
                              ARP.Version0 = '11.0.01' 
                         THEN 'Adobe Reader XI (11.0.01) is  Complaint' 
                         ELSE 'Adobe Reader XI (11.0.01) is not  Complaint' 
                    END) as Reader, 
       MIN(DISTINCT CASE WHEN ARP.DisplayName0 = 'QuickTime' AND 
                              ARP.Version0 = '7.73.80.64' 
                         THEN 'Apple QuickTime is  Complaint' 
                         ELSE 'Apple QuickTime is not  Complaint' 
                    END) as Quicktime, 
       MIN(DISTINCT CASE WHEN ARP.DisplayName0 = 'McAfee Host Intrusion Prevention' AND 
                              ARP.Version0 = '8.00.0202' 
                         THEN 'McAfee HIPS is  Complaint' 
                         ELSE 'McAfee HIPS is not  Complaint' 
                    END) as 'McAfee HIPS'
FROM dbo.v_Add_Remove_Programs AS ARP 
RIGHT OUTER JOIN dbo.v_R_System AS SYS ON ARP.ResourceID = SYS.ResourceID
WHERE (SYS.Netbios_Name0 = 'ese-pkg-04a')
GROUP BY SYS.Netbios_Name0, SYS.ResourceID

返回的内容:

Reader                                   Quicktime                         McAfee HIPS
Adobe Reader XI (11.0.01) is  Complaint  Apple QuickTime is not Complaint  McAfee HIPS is not  Complaint

我想要的格式:

  • Reader Adob​​e Reader XI (11.0.01) 是投诉
  • Quicktime Apple QuickTime 不是投诉
  • McAfee Hips McAfee HIPS 不是投诉
4

1 回答 1

0

尝试:

SELECT MIN(CASE DN.Name
                WHEN 'Adobe Reader XI (11.0.01)'
                THEN CASE ARP.Version0 WHEN '11.0.01' 
                         THEN 'Adobe Reader XI (11.0.01) is  Complaint' 
                         ELSE 'Adobe Reader XI (11.0.01) is not  Complaint' 
                     END
                WHEN 'QuickTime'
                THEN CASE ARP.Version0 WHEN '7.73.80.64' 
                         THEN 'Apple QuickTime is  Complaint' 
                         ELSE 'Apple QuickTime is not  Complaint' 
                     END
                WHEN 'McAfee Host Intrusion Prevention'
                THEN CASE ARP.Version0 WHEN '8.00.0202' 
                         THEN 'McAfee HIPS is  Complaint' 
                         ELSE 'McAfee HIPS is not  Complaint' 
                     END
           END) as Complaint
FROM (SELECT 'Adobe Reader XI (11.0.01)' Name UNION ALL
      SELECT 'QuickTime' UNION ALL
      SELECT 'McAfee Host Intrusion Prevention') AS DN
CROSS JOIN dbo.v_R_System AS SYS 
LEFT JOIN dbo.v_Add_Remove_Programs AS ARP 
  ON ARP.ResourceID = SYS.ResourceID AND ARP.DisplayName0 = DN.Name
WHERE SYS.Netbios_Name0 = 'ese-pkg-04a'
GROUP BY SYS.Netbios_Name0, DN.Name
于 2013-06-27T14:40:19.550 回答