Reputation: 282
I need to count how many times certain value occurs in a column
It looks like this (select * from znajezyki order by klos
)
klos - is a serial number of a person (this value is repeated)
Now I need to create a query that will show me how many people knows 1,2,3 languages
If the same "klos" value is repeated 2 times that means that this person knows 2 languages if it occurs 3 times that means that pearson knows 3 languages and so on
I'd like my result to look something like this:
I tried refering to this post here but i cannot understand it and can't get it to work
I hope y'all can understand what I am talking about :)
Upvotes: 0
Views: 56
Reputation: 664930
First do the simple thing: count how many languages each person knows
SELECT klos, COUNT(*) AS langs
FROM znajezyki
GROUP BY klos
Then use that result in a subquery to count the people by how many languages they know:
SELECT langs, COUNT(*) AS persons
FROM (
SELECT klos, COUNT(*) AS langs
FROM znajezyki
GROUP BY klos
) AS temp
GROUP BY langs
Upvotes: 1