在SQL中将两个列值相加
我创建了一个查询,以获取SCCM中的Win 7和Win 10计数。一切正常,但输出不是我想要的 电流输出在SQL中将两个列值相加,sql,sql-server,Sql,Sql Server,我创建了一个查询,以获取SCCM中的Win 7和Win 10计数。一切正常,但输出不是我想要的 电流输出 DeploymentName CollectionName Available Deadline ReportTime W10 W7 WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 14116 0 WKS 2019-10 WKS 2019-10 20:23.0
DeploymentName CollectionName Available Deadline ReportTime W10 W7
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 14116 0
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 27 0
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 0 2886
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 0 1
DeploymentName CollectionName Available Deadline ReportTime W10 W7
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 14143 2887
预期产出
DeploymentName CollectionName Available Deadline ReportTime W10 W7
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 14116 0
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 27 0
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 0 2886
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 0 1
DeploymentName CollectionName Available Deadline ReportTime W10 W7
WKS 2019-10 WKS 2019-10 20:23.0 00:00.0 18:00.0 14143 2887
我创建的查询
SELECT
CIA.AssignmentName as DeploymentName, CIA.CollectionName as CollectionName, CIA.CreationTime as Available,
CIA.EnforcementDeadline as Deadline, CIA.StartTime as ReportTime, --OPSYS.Caption0 as [Operating System],
--COUNT(*) AS 'Count' ,
sum ( CASE
WHEN OPSYS.Caption0 = 'Microsoft Windows 10 Enterprise' or OPSYS.Caption0 = 'Microsoft Windows 10 Pro' THEN 1 else 0
END ) As 'W10',
sum ( CASE
WHEN OPSYS.Caption0 = 'Microsoft Windows 7 Enterprise' or OPSYS.Caption0 = 'Microsoft Windows 7 Entreprise' THEN 1 else 0
END ) As 'W7'
FROM v_GS_OPERATING_SYSTEM OPSYS
inner join V_R_System sys on OPSYS.ResourceID=sys.ResourceID
Inner join v_FullCollectionMembership FCM on FCM.ResourceID = SYS.ResourceID
--Inner join v_Collection COL on fcm.CollectionID = col.CollectionID
inner join v_CIAssignment CIA on CIA.CollectionID = FCM.CollectionID
WHERE
CIA.AssignmentName = 'WKS 2019-10 '
group by CIA.AssignmentName, CIA.CollectionName, CIA.CreationTime,
CIA.EnforcementDeadline, CIA.StartTime, OPSYS.Caption0
我做错了什么?从
组中删除标题:
group by CIA.AssignmentName, CIA.CollectionName, CIA.CreationTime,
CIA.EnforcementDeadline, CIA.StartTime
为什么要按聚合中的列进行分组?