Questions with a particular tag, ordered by score and views

0

Please login or register to vote for this query.

(click on this box to dismiss)

Law

Q&A for legal professionals, students, and others with experience or interest in law

-- Copy & paste your "favorite tags" from a StackExchange site.

-- Note: As data.stackexchange.com is updated only once a week,
-- you'll see bounties which are put shortly after the update
-- very late.

DECLARE @text VARCHAR(256) = ##WhitespaceSeparatedTags:String##;

SELECT 
    p.CreationDate,
    p.Id as [Post Link],
    p.Tags,
    p.Score,
    p.ViewCount

FROM Posts p
LEFT JOIN PostTags pt ON p.Id = pt.PostId
LEFT JOIN Tags t ON pt.TagId = t.Id

WHERE
-- is question
p.PostTypeId = 1
-- question contains one of the given tags
AND CONCAT(' ', @text, ' ') LIKE CONCAT('% ', t.TagName COLLATE DATABASE_DEFAULT, ' %')

GROUP BY p.Id, p.CreationDate, p.Tags, p.Score, p.ViewCount

ORDER BY p.Score DESC, p.ViewCount DESC

Enter Parameters

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