Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
计算T-SQL中的唯一结果_Sql_Tsql_Aggregate Functions - Fatal编程技术网

计算T-SQL中的唯一结果

计算T-SQL中的唯一结果,sql,tsql,aggregate-functions,Sql,Tsql,Aggregate Functions,我的问题是: SELECT DISTINCT IncidentStatus.IncidentStatusName, Incident.IncidentID AS Bob FROM Incident INNER JOIN IncidentMember ON Incident.IncidentID = IncidentMember.IncidentId INNER JOIN IncidentStatus

我的问题是:

SELECT DISTINCT IncidentStatus.IncidentStatusName, Incident.IncidentID AS Bob
FROM            Incident 
INNER JOIN      IncidentMember 
                 ON Incident.IncidentID = IncidentMember.IncidentId
INNER JOIN      IncidentStatus 
                 ON Incident.IncidentStatusID = IncidentStatus.IncidentStatusID
WHERE        (IncidentMember.MemberId = 6)
结果是:

IncidentStatusName   Bob
---------------------------
Closed               9267
In Progress          9251
In Progress          9289
New                  7893
Resolved             7750
要求的结果是:

IncidentStatusName   Bob
---------------------------
Closed               1
In Progress          2
New                  1
Resolved             1

请求帮助。

从select distinct子句中取出PK字段Incident.incided

从select distinct子句中取出PK字段Incident.incided

SELECT IncidentStatus.IncidentStatusName, COUNT(Incident.IncidentID) AS Bob  
  FROM Incident 
INNER JOIN IncidentMember ON Incident.IncidentID = IncidentMember.IncidentId 
INNER JOIN IncidentStatus ON Incident.IncidentStatusID = IncidentStatus.IncidentStatusID 
WHERE (IncidentMember.MemberId = 6)
GROUP BY IncidentStatus.IncidentStatusName
或者您可能需要
计数(DISTINCT IncidentID)
(取决于您的表结构)


或者你可能需要
COUNT(DISTINCT IncidentID.IncidentID)
(取决于你的表结构)

需要样本数据、带列的表名等。告诉我们你有太多行没有帮助。需要样本数据、带列的表名等。告诉我们你有太多行没有帮助。我承认。你跑得更快。:)+1在这里你必须快一点……:)我承认。你跑得更快。:)+1在这里你必须快一点……:)