Get accepted answers with code snippets in c, as well as upvote and downvote counts

1

Please login or register to vote for this query.

(click on this box to dismiss)

Quantitative Finance Meta

Q&A about the site for finance professionals and academics

WITH AcceptedAnswer AS (
    SELECT TOP 10000  --just get first 10 for now to reduce wait time
        p.Body, 
        p.Id,
        p.Id AS [Post Link],
        p.OwnerDisplayName
    FROM Posts p
    WHERE p.Id IN (
        SELECT AcceptedAnswerId 
        FROM Posts 
        WHERE AcceptedAnswerId IS NOT NULL
        AND Tags LIKE '%<c++>%'  --checking for c right now can change language here
    ) 
    AND p.Body LIKE '%<pre>%'  --answer with code snippets only
    ORDER BY p.Id
)
SELECT
    aa.[Post Link], 
    aa.Body, 
    aa.OwnerDisplayName,
    COUNT(CASE WHEN v.VoteTypeId = 2 THEN 1 END) AS Upvotes, 
    COUNT(CASE WHEN v.VoteTypeId = 3 THEN 1 END) AS Downvotes
FROM AcceptedAnswer aa
JOIN Votes v ON aa.Id = v.PostId
GROUP BY aa.Body, aa.[Post Link], aa.OwnerDisplayName
ORDER BY aa.[Post Link]

Enter Parameters

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