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 |
I know the sql query would be
SELECT DISTINCT COUNT(*) AS count,
COUNT(*) OVER (PARTITION BY COUNT(*)) AS numberOfTimes FROM tablename GROUP BY Name;
But I am not sure how to write this in LINQ
Actually a double grouping gives the intended result.
You can test it from here. Explained version,