Average Number of Answers if has accepted vs none accepted

0

Please login or register to vote for this query.

(click on this box to dismiss)

Returns the average number of answers from all Q&As with at least 1 answer where the Question has an accepted answer vs questions that don't have accepted answers. The theory is that questions that have accepted answers may discourage more answers being added.

Stack Overflow

Q&A for professional and enthusiast programmers

WITH Accepted AS (
SELECT
  xID = 1,
  AVG(CAST(p.AnswerCount AS FLOAT)) AS AcceptedCount
FROM 
  Posts p INNER JOIN Posts a ON p.Id = a.ParentId INNER JOIN Votes v ON a.Id = v.PostId
WHERE 
  p.PostTypeId = 1 AND 
  p.AnswerCount > 0 AND 
  v.VoteTypeId = 1 AND
  p.AcceptedAnswerID IS NOT NULL),
  
NoAccepted AS (  
SELECT
  xID = 1,
  AVG(CAST(p.AnswerCount AS FLOAT)) AS NoAcceptedCount
FROM 
  Posts p
WHERE 
  p.PostTypeId = 1 AND 
  p.AnswerCount > 0 AND 
  p.AcceptedAnswerID IS NULL)
  
SELECT 
  AcceptedCount,
  NoAcceptedCount
FROM
  Accepted a INNER JOIN NoAccepted na ON a.xID = na.xID

Enter Parameters

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