select t.Name, COUNT(*) from PostNotices pn inner join ( ...

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

select t.Name, COUNT(*) from PostNotices pn
inner join
( -- subquery that finds (questionId, ealiestAnswerDate) for all questions
    select q.Id, min(ans.CreationDate) AS earliestAnswerDate from Posts q
    left join Posts ans on q.Id = ans.parentId
    where q.PostTypeId = 1 and q.CreationDate > '2017-01-01'
    group by q.Id
) p on p.Id = pn.PostId
inner join PostNoticeTypes t on t.Id = pn.PostNoticeTypeId
where p.earliestAnswerDate > pn.CreationDate or p.earliestAnswerDate IS NULL
group by t.Name

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results