1

(click on this box to dismiss)

View vote counts on self-answered questions.

Q&A for community managers, administrators, and moderators

``````-- AnswerDelay: Max time between Q and A in min
-- VoteDelay: Votes in first N days
declare @vote_delay int = ##VoteDelay:int?5##

select q.Id,
--sum(case when v.PostId = q.Id then 1 else 0 end) as [Q],
sum(case when v.VoteTypeId = 2 and v.PostId = q.Id then 1 else 0 end)
as [Q↑],
sum(case when v.VoteTypeId = 3 and v.PostId = q.Id then 1 else 0 end)
as [Q↓],
--sum(case when v.PostId = a.Id then 1 else 0 end) as [A],
sum(case when v.VoteTypeId = 2 and v.PostId = a.Id then 1 else 0 end)
as [A↑],
sum(case when v.VoteTypeId = 3 and v.PostId = a.Id then 1 else 0 end)
as [A↓]
--sum( as [Tot],
--sum(case when v.VoteTypeId = 2 and v.PostId in (q.Id, a.Id) then 1 else 0 end)
--    as [Tot↑],
--sum(case when v.VoteTypeId = 3 and v.PostId in (q.Id, a.Id) then 1 else 0 end)
--    as [Tot↓]
into #table
from Posts q
inner join Posts a on a.PostTypeId = 2
and q.OwnerUserId = a.OwnerUserId
and a.ParentId = q.Id
and datediff(minute, q.CreationDate, a.CreationDate) <= @answer_delay
inner join Votes v on v.PostId in (q.Id, a.Id)
and v.VoteTypeId in (2, 3)
and datediff(day, q.CreationDate, v.CreationDate) <= @vote_delay
group by q.Id, q.Score, a.Id, a.Score

[Q↑]-[Q↓] as [Q], [Q↑], [Q↓],
[A↑]-[A↓] as [A], [A↑], [A↓],
[Q↑]+[A↑]-[Q↓]-[A↓] as [Tot],
[Q↑]+[A↑] as [Tot↑],
[Q↓]+[A↓] as [Tot↓]
from #table
order by Id``````

### Enter Parameters

Options:
-
Switch sites:
Hold tight while we fetch your results
:records returned in :time ms:cached