SQL group by number of graphs

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; 

The returned table looks like this:

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

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

Some return values ​​Like:

 2 ---550 3 ---545 

Is there a way without using a new table or template table or any storage table only on request?

+4
source share
3 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] 
+10
source

you can use

 SELECT [Count Of Register], COUNT(*) FROM (SELECT COUNT([Id]) as [Count Of Register], Tag as [Tag] FROM [Members] GROUP BY Tag) q GROUP BY [Count Of Register] 
+1
source

mysql> create table order1 (counter int (3) not null primary key auto_increment, -> tag int (3)); Request OK, 0 rows affected (0.01 sec)

mysql> insert into order1 (500,20); // insert somany values ​​as u and check insert into order 1 (500, 20); insert into values ​​of the order of 1 (600, 20); mysql> select counter, count (*) from group order1 by counter

0
source

Source: https://habr.com/ru/post/1384065/


All Articles