/*9. For each question (i.e. posts where type = question)...

0

Please login or register to vote for this query.

(click on this box to dismiss)

3D Printing Meta

Q&A about the site for 3D printing enthusiasts

/*9.	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
p.Id, p.Title, count(g.TagId) as TagsCount
From 
Posts p LEFT JOIN PostTypes t
ON p.PostTypeId=t.Id
LEFT JOIN PostTags g
ON p.Id=g.PostId



Group by p.Id, p.Title
Having count(g.TagId)>5 AND
count(g.TagId)=
(Select Top 1 count(g.TagId) 
From Posts p LEFT JOIN PostTags g
ON p.Id=g.PostId
group by p.Id, p.Title
order by count(g.TagId) desc )

order by newid()

Enter Parameters

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