Q5

0

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

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;

Enter Parameters

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