SQL query, group by and number of occurrences I have the following table (only one column):

X
----
1
1
1
2
2
3
3
3
4
4
5
6
6
7
7
7


I need a SQL query which will output the following:

Occurrences | Number
1  1  * there are only 1 entry with one occurrence (number 5)
2  3  * there are three entries with two occurrences (numbers 2,4,6)
3  2  * there are two entries with three occurrences (numbers 1 and 7)


If I do something like this:

select count(*) FROM (SELECT count(*) as N FROM table 1 GROUP BY x) a GROUP BY a.N;


I get the correct results, but only the second column t with the number of occurrences. 
Does anyone know how to get the complete output as in the example above?
This should work:

select count(*), a.N FROM (SELECT count(*) as N FROM table1 GROUP BY x) a GROUP BY a.N;


SQLFiddle

Note that it gives you 3 for N = 3, because there are actually three number repeated thrice: 1, 3 and 7.