0

This is something I am not getting for some or other reason.

I have a list of records

BusinessUnitId     Position      Date          Time
-----------------------------------------------------------
76                 Staff         3/30/2009     11:00:00 AM
76                 Staff         3/30/2009     04:00:00 PM
76                 Management    3/30/2009     05:00:00 PM
78                 Exco          3/30/2009     09:00:00 AM
78                 Staff         3/30/2009     09:30:00 AM

If I do a group by

select 
    count(answer.BusinessUnitId)
from 
    AnswerSelected answer
group by 
    answer.BusinessUnitId

I retrieve a value of 3 and 2

What I am trying to achieve is get a count of 2

So in total 2 business units submitted answers, 76 and 78(hope this makes sense)

How can I do this?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Arianule
  • 8,811
  • 45
  • 116
  • 174

1 Answers1

2

Use COUNT(DISTINCT ...)

SELECT
    COUNT(DISTINCT BusinessUnitId)
FROM AnswerSelected

You don't need to use GROUP BY in this particular case to get the distinct count of business units across your entire table.

Demo here:

Rextester

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360