WITH posts_tags AS ( SELECT postid, STRING_AGG(tagname, '...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

Q&A for Ubuntu users and developers

WITH posts_tags AS (
  SELECT
    postid,
    STRING_AGG(tagname, ' ') WITHIN GROUP (ORDER BY tagname) as tags
  FROM
    posts p
    INNER JOIN posttags pt ON p.id = pt.postid
    INNER JOIN tags t ON pt.tagid = t.id
  GROUP BY
    postid
)
SELECT
  tags,
  COUNT(*) as count
FROM posts_tags
GROUP BY
  tags
ORDER BY
  count DESC
OFFSET 0 ROWS
FETCH NEXT 10 ROWS ONLY

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results