How many questions with accepted answer accepted my answer

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

WITH sq1 AS (
  SELECT
      a.Id
    , CASE WHEN q.AcceptedAnswerId IS NULL THEN 0 ELSE 1 END answered
    , CASE WHEN q.AcceptedAnswerId = a.Id THEN 1 ELSE 0 END mine
  FROM
      Posts a
  INNER JOIN
      Posts q
  ON
      a.ParentId = q.Id
  WHERE
      a.OwnerUserId = ##UserId##
)
SELECT
    SUM(sq1.Id) AS answers
  , SUM(sq1.answered) AS answered
  , SUM(sq1.mine) AS mine
  , CONVERT(decimal(4,2)
      ,( CONVERT(decimal(10),SUM(sq1.answered))
        /CONVERT(decimal(10),SUM(sq1.Id))
       )
    ) AS pct_answered
FROM
    sq1

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results