Q&A for scientists using computers to solve scientific problems
SELECT TOP 10 STRING_AGG(t.TagName, ', ') AS Tags, -- Aggregate tag names into a comma-separated list COUNT(t.Id) AS NumberOfTags, -- Count the number of tags for each post p.Id AS PostId, p.OwnerUserId AS UserId, LEFT(p.Body, 300) AS PostBody FROM ( SELECT TOP 5000 -- Process the first 5000 posts to avoid timeouts Id, OwnerUserId, Body FROM Posts WHERE Tags IS NOT NULL -- Ensure the post has tags ORDER BY Id DESC -- Fetch the most recent posts ) AS p JOIN PostTags pt ON p.Id = pt.PostId JOIN Tags t ON pt.TagId = t.Id GROUP BY p.Id, p.OwnerUserId, p.Body HAVING COUNT(t.Id) >= 5 -- Ensure there are at least 5 tags ORDER BY NumberOfTags DESC;