Q&A for gamemasters and players of tabletop, paper-and-pencil role-playing games
with answered_cte AS ( SELECT q.Id AS qid, q.CreationDate AS created, MIN(a.CreationDate) AS answered FROM Posts q INNER JOIN Posts a ON a.ParentId=q.Id WHERE (q.PostTypeId=1) and (q.AnswerCount>0) ---only question which have at least one answer GROUP BY q.Id, q.CreationDate ), times_cte AS (SELECT qid, DATEDIFF(day, created, answered) AS Days FROM answered_cte ) SELECT Days, COUNT(qid) AS Count FROM times_cte GROUP BY Days ORDER BY Days ASC