我正在尝试对一组值进行计数,但计数会带来额外的值。
这是一些背景信息。以下 T-SQL 查询返回我需要的数据:
SELECT DISTINCT [REQ_INFO].UDAValue as 'UDA value', REQ_INFO.ProjectID,
REQ_INFO.BaselineID, Req_ID
FROM [REQ_INFO]
INNER JOIN [Project_INFO] ON [REQ_INFO].[ProjectID]=[Project_INFO].[ProjectID]
INNER JOIN [Baseline_INFO]ON [REQ_INFO].[BaselineID]=[Baseline_INFO].[BaselineID]
WHERE [Project_INFO].[Name] = 'Address Book'
AND [Baseline_INFO].Name = 'Current Baseline'
AND [UDAName] = 'Requirement Priority'
ORDER BY REQ_INFO.Req_ID
这将返回以下数据:
我还需要计算每个值在 UDA 值列中出现的次数。如上所示,总和应为 11。但是我尝试了以下代码,但它正在计算额外的行:
SELECT [REQ_INFO].UDAValue as 'UDA value',COUNT (*) as 'UDA Num'
FROM [REQ_INFO]
INNER JOIN [Project_INFO] ON [REQ_INFO].[ProjectID]=[Project_INFO].[ProjectID]
INNER JOIN [Baseline_INFO]ON [REQ_INFO].[BaselineID]=[Baseline_INFO].[BaselineID]
WHERE [Project_INFO].[Name] = 'Address Book'
AND [Baseline_INFO].Name = 'Current Baseline'
AND [UDAName] = 'Requirement Priority'
GROUP BY REQ_INFO.UDAValue
有人对我做错了什么有建议吗?