SELECT TOP 10 Posts.Id, Title, COUNT(PostTags.PostId) AS ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Emacs

Q&A for those using, extending or developing Emacs

-- For each question (i.e. posts where type = question), count the total 
-- number of tags – do this only for posts that have more than 5 tags associated 
-- with them. Display 10 random posts with the highest number of tags.
SELECT TOP 10 Posts.Id,
  Title,
  COUNT(PostTags.PostId) AS TagCount
FROM PostTypes INNER JOIN Posts
    ON (PostTypes.Id = Posts.PostTypeId)
    INNER JOIN PostTags
    ON (Posts.Id = PostTags.PostId)
WHERE PostTypes.Name = 'Question' 
  AND (SELECT COUNT(*) FROM PostTags WHERE PostId = Posts.Id) = 5
GROUP BY Posts.Id, Title
ORDER BY TagCount DESC, NEWID();

Enter Parameters

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