1
我正在嘗試獲取用戶提供活動作爲查詢一部分的最近活動日期。下面是該查詢:獲取另一列不等於零的列的最大日期
USE SCRUMAPI2
DECLARE @userParam VARCHAR(100)
,@statusParam VARCHAR(100)
SET @userParam = '%'
SET @statusParam = '%'
SELECT ROW_NUMBER() OVER (
ORDER BY TSK.[Status] DESC
) AS 'RowNumber'
,PDT.[Name] AS Project
,(
CASE WHEN (
STY.KanBanProductId IS NOT NULL
AND STY.SprintId IS NULL
) THEN 'KanBan' WHEN (
STY.KanBanProductId IS NULL
AND STY.SprintId IS NOT NULL
) THEN 'Sprint' END
) AS ProjectType
,STY.[Number] StoryNumber
,STY.Title AS StoryTitle
,TSK.[Name] AS Task
,CONVERT(VARCHAR(20), STY.Effort) AS Effort
,CONVERT(VARCHAR(20), TSK.OriginalEstimateHours) AS OriginalEstimateHours
,ISNULL(SUM(DTH.[Hours]), 0) AS [TotalHours]
,TSK.[Status] AS [Status]
FROM Task TSK
LEFT JOIN DailyTaskHours DTH ON TSK.PK_Task = DTH.TaskId
LEFT JOIN Story STY ON TSK.StoryId = STY.PK_Story
LEFT JOIN Sprint SPT ON STY.SprintId = SPT.PK_Sprint
LEFT JOIN Product PDT ON STY.ProductId = PDT.PK_Product
WHERE TSK.PointPerson LIKE @userParam
AND TSK.[Status] LIKE @statusParam
GROUP BY LEN(STY.[Number])
,STY.[Number]
,TSK.[Status]
,STY.Title
,PDT.[Name]
,TSK.CreateDate
,TSK.[Name]
,STY.KanBanProductId
,STY.SprintId
,TSK.OriginalEstimateHours
,STY.Effort
ORDER BY CASE TSK.[Status] WHEN 'Not Started' THEN 1 WHEN 'In Progress' THEN 2 WHEN 'Impeded' THEN 3 WHEN 'Done' THEN 4 END
我想用的功能添加行,像這樣:
,MAX(DTH.ActivityDate WHERE DTH.Hours != 0) AS LatestActivityDate
然而,這將導致一個語法錯誤。我無法將DTH.Hours!= 0添加到WHERE語句中,因爲我不想讓整個查詢過濾掉它。那麼如何獲得最新的ActivityDate,其中小時數不等於零?
這裏是什麼DTH表看起來像以供參考:
嘗試使用自子查詢加入'(選擇MAX(DTH2 .ActivityDate)從DailyTaskHours DTH2 WHERE dth.taskID = dth2.taskID和DTH2.Hours!= 0)' –