1

質問があります:

   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]

If: SUM(DTH.[Hours]) AS Total = 0 行を返さないようにしたい

アプローチは CASE WHEN を使用することだと思いますが、それがどこに行くのか正確に把握するのに苦労しています。

4

2 に答える 2

15

havingの後に句を追加しgroup byます。

HAVING SUM(DTH.[Hours]) <> 0 
于 2013-09-18T16:13:34.417 に答える
7

追加するだけです:

HAVING SUM(DTH.[Hours]) > 0

クエリの最後に。

于 2013-09-18T16:13:25.137 に答える