需要计数带有特定版本的chrome

时间:2018-12-30 08:26:55

标签: sql sccm

iam使用SCCM视图/表制作饼图报告。 需要计数具有特定版本的google chrome的模型。

使用以下查询

select distinct v_R_System_Valid_Alias.Netbios_Name0 AS [Computer Name],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedName AS [Product Name],
      [Publisher] = CASE when (ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedPublisher, N'-1') = N'-1') then @UnknownLoc
      Else v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedPublisher
      End,
      [Version] = CASE when (ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedVersion, N'-1')  = N'-1') then @UnknownLoc
      Else v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedVersion
      End,
      [Language] = CASE when (ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.Language0, -1) < 0) then @UnknownLoc
      Else CAST(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.Language0 as nvarchar)
      End,
      ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.InstallType0, 0) as [Installation Type],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.FamilyName AS [Product Family],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.CategoryName AS [Product Category],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.ProductID0 AS [ProductID],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.SoftwareID as [Software ID],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.CM_DSLID0 AS [DSL ID]
     FROM fn_rbac_GS_INSTALLED_SOFTWARE_CATEGORIZED(@UserSIDs) v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias
      INNER JOIN fn_rbac_R_System_Valid(@UserSIDs) v_R_System_Valid_Alias on v_R_System_Valid_Alias.ResourceID = v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.ResourceID   
    where productName0 like '%Google Chrome%'
      order by v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedName, Publisher, Version

它给了我以下输出

enter image description here

我需要带有型号名称的不同版本 输出应该是

version count(models)
 69.0    2000

我需要在没有光标的情况下实现此目标吗?

2 个答案:

答案 0 :(得分:1)

您可以将查询作为子查询

select [Computer Name],  [Version], count(*)
from (
    select distinct v_R_System_Valid_Alias.Netbios_Name0 AS [Computer Name],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedName AS [Product Name],
      [Publisher] = CASE when (ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedPublisher, N'-1') = N'-1') then @UnknownLoc
      Else v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedPublisher
      End,
      [Version] = CASE when (ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedVersion, N'-1')  = N'-1') then @UnknownLoc
      Else v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.NormalizedVersion
      End,
      [Language] = CASE when (ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.Language0, -1) < 0) then @UnknownLoc
      Else CAST(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.Language0 as nvarchar)
      End,
      ISNULL(v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.InstallType0, 0) as [Installation Type],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.FamilyName AS [Product Family],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.CategoryName AS [Product Category],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.ProductID0 AS [ProductID],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.SoftwareID as [Software ID],
      v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.CM_DSLID0 AS [DSL ID]
     FROM fn_rbac_GS_INSTALLED_SOFTWARE_CATEGORIZED(@UserSIDs) v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias
      INNER JOIN fn_rbac_R_System_Valid(@UserSIDs) v_R_System_Valid_Alias on v_R_System_Valid_Alias.ResourceID = v_GS_INSTALLED_SOFTWARE_CATEGORIZED_Alias.ResourceID   
    where productName0 like '%Google Chrome%'
 ) t 
 order by [Computer Name],  [Version]

答案 1 :(得分:-1)

这不只是一个简单的WHERE子句和汇总吗?

SELECT isc.NormalizedVersion, COUNT(*)
FROM fn_rbac_GS_INSTALLED_SOFTWARE_CATEGORIZED(@UserSIDs) isc JOIN
     fn_rbac_R_System_Valid(@UserSIDs) sv 
     ON sv.ResourceID = isc.ResourceID   
WHERE isc.productName0 like '%Google Chrome%' AND
      isc.NormalizedVersion = N'69.0'
GROUP BY isc.NormalizedVersion;