Get Answered / Accepted Percentages

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

--Don't hate me, I haven't done SQL in a while :/

--Use time interval 
DECLARE @StartDate datetime = '1970-01-01 00:00:00';
DECLARE @EndDate datetime = '2021-02-20 00:00:00';

--Use minimum score
DECLARE @MinimumScore int = 0;

--Use minimum viewcount
DECLARE @MinimumViewCount int = 0;

--Percentage of Posts with accepted answers

SELECT
  (CAST(Count(n.Id) AS float) / (SELECT Count(*) FROM Posts o WHERE PostTypeId = 2) * 100) AS AcceptedPercentage 
FROM 
  Posts n
    INNER JOIN
  Posts o ON n.Id = o.AcceptedAnswerId
WHERE 
    n.Score >= @MinimumScore
  AND 
    n.ViewCount >= @MinimumViewCount
  AND
    n.CreationDate BETWEEN @StartDate AND @EndDate;

Enter Parameters

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