Questions with one downvote and multiple upvotes per tag

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @tagparam varchar(100) = ##TagName##
DECLARE @from DATE = ##From##
DECLARE @to DATE = ##To##

SELECT
(
SELECT COUNT(T1.Id) FROM
(
SELECT
p.Id as Id
, (SELECT COUNT(v.Id) FROM Votes v WHERE v.PostId = p.Id AND v.VoteTypeId = 2) as UpVotes
, (SELECT COUNT(v.Id) FROM Votes v WHERE v.PostId = p.Id AND v.VoteTypeId = 3) as DownVotes
FROM posts p
INNER JOIN postTags pt ON p.Id = pt.PostId
INNER JOIN Tags t ON pt.TagId = t.Id
WHERE t.TagName = @tagparam
AND p.CreationDate >= @from
AND p.CreationDate < @to
) T1
WHERE T1.UpVotes >= 1
AND T1.DownVotes = 1
) AS OneDownMultipleUpQuestions
,
(
SELECT COUNT(p.Id)
FROM posts p
INNER JOIN postTags pt ON p.Id = pt.PostId
INNER JOIN Tags t ON pt.TagId = t.Id
WHERE t.TagName = @tagparam
AND p.CreationDate >= @from
AND p.CreationDate < @to
) AS QuestionsTotal

Enter Parameters

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