去掉Sql查询语句查询结果中字段值为0的数据

时间:2022-01-29 15:35:07
去掉Sql查询语句查询结果中字段值为0的数据

sql语句:
SELECT  (b.cFullName+b.MiddleName+b.cEnglishName) AS UserName ,sum(a.Integral) AS Integral
FROM AI_Integral  AS a LEFT JOIN dbo.Employees AS b ON a.EmployeeID=b.cEmployeeID  
WHERE 1=1   and b.cEmployeeID not in('123401','123402','123403','123404','123405','123407','123408',
'123409','123410','123411','123412','123413','123414','123415','123416','123417','123418','123419','123420','123421')  
and (CAST (YEAR(WorkDate) AS NVARCHAR(4))+'-'+CAST(MONTH(WorkDate) AS NVARCHAR(2)))='2016-4'  
GROUP BY b.cFullName+b.MiddleName+b.cEnglishName 


我语句中应该添加什么才能去除图片中 Integral字段值为0.0的那一行数据?

6 个解决方案

#1


and Integral <> 0.0 ?

#2


with cte (username,integral) as
(
select '张三',0.1 union
select '何旭东',0.0 union
select '李四',-0.2 union
select '王五',-0.1 union
select '赵六',0.3 
)
select * from cte where integral<>0

#3


引用 1 楼 guwei4037 的回复:
and Integral <> 0.0 ?

试过了,结果没变

#4


在最后加段having

having sum(a.Integral) != 0

#5


引用 2 楼 qq_18219519 的回复:
with cte (username,integral) as
(
select '张三',0.1 union
select '何旭东',0.0 union
select '李四',-0.2 union
select '王五',-0.1 union
select '赵六',0.3 
)
select * from cte where integral<>0

可以解决

#6


引用 4 楼 starfd 的回复:
在最后加段having

having sum(a.Integral) != 0

也可以解决

#1


and Integral <> 0.0 ?

#2


with cte (username,integral) as
(
select '张三',0.1 union
select '何旭东',0.0 union
select '李四',-0.2 union
select '王五',-0.1 union
select '赵六',0.3 
)
select * from cte where integral<>0

#3


引用 1 楼 guwei4037 的回复:
and Integral <> 0.0 ?

试过了,结果没变

#4


在最后加段having

having sum(a.Integral) != 0

#5


引用 2 楼 qq_18219519 的回复:
with cte (username,integral) as
(
select '张三',0.1 union
select '何旭东',0.0 union
select '李四',-0.2 union
select '王五',-0.1 union
select '赵六',0.3 
)
select * from cte where integral<>0

可以解决

#6


引用 4 楼 starfd 的回复:
在最后加段having

having sum(a.Integral) != 0

也可以解决