SQL Group by Count of Counts

This is my script

SELECT COUNT( [Id]) as [Count Of Register],
Tag as [Tag]
FROM [Members]
Group By Tag 
Order By [Count Of Register] Desc;

Returned table is like this:

Count   Tag

550 ----1
550 ----2
545 ----3
545 ----4
545 ----5

So, this time I need Count of Tag, Group by this new Count field.

Some Returned Values Like:

2 ---550
3 ---545

Is there any way without using new table or Template Table or any Storage Table just by query?

Answers


SELECT [Count Of Register], COUNT(1) [Grouped Count]
FROM
(
    SELECT COUNT( [Id]) as [Count Of Register],
           Tag as [Tag]
    FROM [Members]
    Group By Tag 

) MyTable
GROUP BY [Count Of Register]

Need Your Help

how to find user id from session_data from django_session table?

python django base64 pickle pinax

In django_session table session_data is stored which is first pickled using pickle module of python and then encoded in base64 by using base64 module of python.

Get unique id at the same time get the sum of value for each id

mysql sql

I want to get all unique ID from table and get sum of value from value_1 to value_640 for each unique ID.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.