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 に答える