Answer the question
In order to leave comments, you need to log in
Query in SQL. How to make a selection of pairs and triplets of the most frequent values (from different tables)?
How to make a selection of pairs and triplets of the most frequent values?
Answer the question
In order to leave comments, you need to log in
SELECT *
FROM
(
SELECT t1.*,
RANK() OVER(ORDER BY cnt DESC PARTITION BY city) AS rn2
FROM
(
SELECT city, hobby, COUNT(hobby) AS cnt
FROM table
GROUP BY city, hobby
) AS t1
ORDER BY city, cnt DESC
) AS t1
WHERE rn2=1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question