Return every row that contains the most occurring value

This question may seem similar to a common question that asks to return the most occurring value. However, I need to list every row containing the value that occurs most often.

In my example there is a zipCode that appears 3 times (the most out of any zip code). I would like to list every occurrence of that zip code without having to know which zip code has the most occurrences at the time of the query.

My Query:

SELECT *, COUNT(zipCode) AS NumOccurrences
FROM customers
GROUP BY zipCode
ORDER BY NumOccurrences DESC
LIMIT 1

Returns:

enter image description here

What I want to return:

enter image description here

Without using this query obviously:

SELECT *
FROM customers
WHERE zipCode = 10001

I want to return each of the 3 occurrences of that zip code and not just the first instance of it. Without having to use the query above because I may not now which zip code occurs the most at the time of the query.



from Recent Questions - Stack Overflow https://ift.tt/3dRslpV
https://ift.tt/37VfIWT

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations