0

I need to count how many times certain value occurs in a column

It looks like this (select * from znajezyki order by klos)

enter image description here

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: enter image description here

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 :)

antekkalafior
  • 274
  • 2
  • 16

1 Answers1

1

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
Bergi
  • 630,263
  • 148
  • 957
  • 1,375