Z
Z
zaharoffff2016-03-28 14:25:15
SQL
zaharoffff, 2016-03-28 14:25:15

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

1 answer(s)
M
mletov, 2016-03-28
@zaharoffff

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

Here is a very rough solution showing which direction to think. Without a specific example with test data, the task is still completely incomprehensible to me.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question