SELECT p.Id AS QuestionId, p.Title AS QuestionTitle, p.Ta...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Drones and Model Aircraft Meta

Q&A for experienced flyers, pilots, and builders of drones and model aircraft

SELECT 
    p.Id AS QuestionId,
    p.Title AS QuestionTitle,
    p.Tags AS TagSet,
    CASE 
        WHEN CHARINDEX('><', p.Tags) > 0 THEN LEFT(p.Tags, CHARINDEX('><', p.Tags) - 1)
        ELSE p.Tags
    END AS PrimaryTag, -- Extracts the first tag or the whole tag if there's only one
    p.Score AS UpVotes, -- Assuming 'Score' is the upvotes count for the question
    u.DisplayName AS QuestionUser,
    u.Reputation AS UserReputation,
    p.CreationDate AS QuestionCreationTime,
    (
        SELECT MIN(CreationDate) 
        FROM Posts 
        WHERE ParentId = p.Id AND PostTypeId = 2
    ) AS FirstAnswerCreationTime,
    a.CreationDate AS AcceptedAnswerCreationTime, -- Directly joins accepted answer time
    a.Score AS AcceptedAnswerUpVotes, -- Accepted answer upvotes
    (
        SELECT COUNT(*) 
        FROM Votes 
        WHERE PostId = a.Id AND VoteTypeId = 3
    ) AS AcceptedAnswerDownVotes,
    p.ViewCount AS TotalViews
FROM 
    Posts p
JOIN 
    Users u ON p.OwnerUserId = u.Id
LEFT JOIN 
    Posts a ON p.AcceptedAnswerId = a.Id -- Join the accepted answer
WHERE 
    p.PostTypeId = 1 -- PostTypeId 1 indicates questions
    AND p.CreationDate >= '2022-12-01' 
    AND p.CreationDate < '2024-12-02'
    AND p.AcceptedAnswerId IS NOT NULL; -- Filters out unanswered questions

Enter Parameters

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