Nikos Allamanis
Nikos Allamanis

Reputation: 61

Finding the most frequent value in SQL column

I have written the following code :

select ap.doctorsnum,doc.specialty
from appointments as ap
join doctor as doc
on ap.doctorsnum = doc.doctorsnum

This a screenshot of the first 10 rows of the result. (The actual result contains more than 5k rows)

enter image description here

How can I calculate which is the most frequent value to appear in the "specialty" column?

(All security numbers are fake, they have been randomly generated)

Any help is much appreciated!

Thank you!

Upvotes: 1

Views: 53

Answers (1)

daniel sp
daniel sp

Reputation: 1000

I would make a query like:

SELECT 
    speciality,
    COUNT(*) AS value_occurrence
FROM appointments 
GROUP BY 
    speciality
ORDER BY value_occurrence DESC
LIMIT 1;

Upvotes: 2

Related Questions