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的那一行数据?
解决方案
20
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
20
在最后加段having
having sum(a.Integral) != 0