I’m trying to return a given number of server names and then a count of how many came back. For instance:
select servername, count(distinct servername) number
from TABLE
where [target] = 'blah'
group by servername
This returns the following:
servername number
server1 1
server2 1
What I’m attempting to get is for the “number” column to read “2,” because there are 2 distinct servernames. This should be incredibly simple, but I’m completely at a loss.
You can use a correlated subquery:
See SQL Fiddle with Demo