Q&A about the site for physical fitness professionals, athletes, trainers, and those providing health-related needs
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 AND (a.CreationDate>q.CreationDate) ---a.CreationDate=q.CreationDate means that it was posted together with the question ---a.CreatioNDate<q.CreationDate meanst that the answer was posted to another question and the two questions were merged GROUP BY q.Id, q.CreationDate ) SELECT top (##num?1000##) qid AS [Post Link], DATEDIFF(month, created, answered) AS Months, DATEDIFF(day, created, answered) AS Days, DATEDIFF(hour, created, answered) AS Hours, DATEDIFF(minute, created, answered) AS Minutes, DATEDIFF(second, created, answered) AS Seconds, created, answered FROM answered_cte ORDER BY seconds ASC