/*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)

Martial Arts Meta

Q&A about the site for students and teachers of all martial arts

/*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) order by count(g.TagId) desc )

ORDER BY newid()

Enter Parameters

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