I have a table like below,
Name | Value |
---|---|
A | Sample1 |
A | Sample2 |
A | Sample3 |
B | Sample3 |
B | Sample1 |
C | Sample2 |
C | Sample3 |
D | Sample1 |
If I group the table by Name to get the count,
Select Name, Count(*) as count from table group by Name;
I will get the following result,
Name | count |
---|---|
A | 3 |
B | 2 |
C | 2 |
D | 1 |
I need to get the number of repetitions of each count. Means desired outcome below,
count | numberOfTimes |
---|---|
3 | 1 |
2 | 2 |
1 | 1 |
2
Answers
Toss your existing sql into a subquery and group once again:
Use
COUNT(*)
window function in your query:See the demo.