count of questions 1 hour,1-5 hours,5-24 hours,1-7 days , more than 7 days

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mythology Meta

Q&A about the site for enthusiasts and scholars of mythology and folklore

SELECT 
    CASE
        WHEN DATEDIFF(HOUR, q.CreationDate, a.CreationDate) <= 1 THEN '1 hour or less'
        WHEN DATEDIFF(HOUR, q.CreationDate, a.CreationDate) <= 5 THEN '1-5 hours'
        WHEN DATEDIFF(HOUR, q.CreationDate, a.CreationDate) <= 24 THEN '5-24 hours'
        WHEN DATEDIFF(DAY, q.CreationDate, a.CreationDate) <= 7 THEN '1-7 days'
        ELSE 'More than 7 days'
    END AS TimeRange,
    COUNT(*) AS SolvedQuestionsCount
FROM Posts q
JOIN Posts a ON q.AcceptedAnswerId = a.Id  -- Join to link questions with their accepted answers
WHERE q.PostTypeId = 1  -- Filter for questions
GROUP BY 
    CASE
        WHEN DATEDIFF(HOUR, q.CreationDate, a.CreationDate) <= 1 THEN '1 hour or less'
        WHEN DATEDIFF(HOUR, q.CreationDate, a.CreationDate) <= 5 THEN '1-5 hours'
        WHEN DATEDIFF(HOUR, q.CreationDate, a.CreationDate) <= 24 THEN '5-24 hours'
        WHEN DATEDIFF(DAY, q.CreationDate, a.CreationDate) <= 7 THEN '1-7 days'
        ELSE 'More than 7 days'
    END
ORDER BY SolvedQuestionsCount DESC;

Enter Parameters

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