如何选择不同并计算所选的?

时间:2016-10-31 12:01:03

标签: sql count ssms distinct

如何选择不同并计算所选的?这是我选择Distinct的代码:

SELECT distinct  [ClientID]
  ,[AssessmentDate]

FROM [dbo].[UserAssessrcads]

我希望它以:

结束
RCADS      62

(或类似的东西)

2 个答案:

答案 0 :(得分:2)

你可以使用dinamic table

  select count(*) from ( 
      SELECT distinct  [ClientID]
              ,[AssessmentDate]
        FROM [dbo].[UserAssessrcads] ) t

答案 1 :(得分:2)

更好的方法是:

SELECT [ClientID],[AssessmentDate], count(1)
FROM [dbo].[UserAssessrcads]
group by [ClientID],[AssessmentDate]