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