我有一个问题:
SELECT DTH.PointPerson AS Person
,PDT.[Name] AS Project
,(CASE WHEN TSK.Name IS NULL THEN NULL
WHEN SPT.[Name]+' - '+SPT.[Description] IS NULL THEN 'KanBan'
ELSE SPT.[Name]+' - '+SPT.[Description]
END) AS Sprint
,COALESCE(STY.[Number], NSS.IncidentNumber) AS Story
,TSK.[Name] AS Task
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 1 THEN DTH.[Hours] ELSE 0 END) AS Monday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 2 THEN DTH.[Hours] ELSE 0 END) AS Tuesday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 3 THEN DTH.[Hours] ELSE 0 END) AS Wednesday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 4 THEN DTH.[Hours] ELSE 0 END) AS Thursday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 5 THEN DTH.[Hours] ELSE 0 END) AS Friday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 6 THEN DTH.[Hours] ELSE 0 END) AS Saturday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 7 THEN DTH.[Hours] ELSE 0 END) AS Sunday
,SUM(DTH.[Hours]) AS Total
FROM DailyTaskHours DTH
LEFT JOIN Task TSK ON DTH.TaskId = TSK.PK_Task
LEFT JOIN Story STY ON TSK.StoryId = STY.PK_Story
LEFT JOIN NonScrumStory NSS ON DTH.NonScrumStoryId = NSS.PK_NonScrumStory
LEFT JOIN Sprint SPT ON STY.SprintId = SPT.PK_Sprint
LEFT JOIN Product PDT ON STY.ProductId = PDT.PK_Product
GROUP BY DTH.PointPerson, PDT.[Name], SPT.[Name]
,SPT.[Description]
,STY.[Number]
,NSS.IncidentNumber
,TSK.[Name]
如果:SUM(DTH。[Hours])AS Total = 0我想要不返回行
我认为这种方法是使用CASE WHEN,但我无法弄清楚确切的位置。
答案 0 :(得分:14)
在having
:
group by
子句
HAVING SUM(DTH.[Hours]) <> 0
答案 1 :(得分:6)
只需添加:
HAVING SUM(DTH.[Hours]) > 0
在您的查询结束时。