April 4, 2014 at 10:47 am
I am trying to get top 20 servers where the servername Count is maximum.
Here is my Query ...
Select Count(Server_Name)ServerCount , Server_Name from Temp1 A
Group By Server_Name
Having COUNT(Server_Name) = (Select MAX(CNT) from (Select Count(Server_Name)as CNT , Server_Name from Temp1 group By Server_Name )A
I can get only one server name which has the maximum # of servers.
I tried top 20 but its not working .. Any ideas?
The Table has this Column called Server Name such as
ABC1111
ABC222
ABC222
ABC222
ABC222
XYZ111
So , I need to get the servername Counts which repeat multiple times and get the max of those for top 20.
(Hope I haven't made it confusing)
April 4, 2014 at 12:12 pm
It would be REALLY helpful if you could provide ddl and sample with your posts.
I am not 100% certain what you are trying to do here but see if this does it.
Select Count(Server_Name)ServerCount , Server_Name
from Temp1 A
Group By Server_Name
order by Count(Server_Name)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 7, 2014 at 5:28 am
select top 20
Servername, count(*)
from tablename
group by servername order by 2
Hope this answers your problem
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply