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)

Physics

Q&A for active researchers, academics and students of physics

WITH sq1 AS (
  SELECT
      u.Id AS UserId
    , u.DisplayName
    , a.Id
    , CASE WHEN q.AcceptedAnswerId IS NULL THEN 0 ELSE 1 END accepted
    , CASE WHEN q.AcceptedAnswerId = a.Id THEN 1 ELSE 0 END mine
  FROM
      Users u
  INNER JOIN
      Posts a
  ON
      a.OwnerUserId = u.Id
  INNER JOIN
      Posts q
  ON
      a.ParentId = q.Id
  WHERE
      u.Id = ##UserId##
)
SELECT
    sq1.UserId
  , sq1.DisplayName
  , COUNT(1) AS answers
  , SUM(sq1.accepted) AS accepted
  , SUM(sq1.mine) AS mine
  , CONVERT(decimal(5,2)
      ,( CONVERT(decimal(10),SUM(sq1.accepted))
       / CONVERT(decimal(10),COUNT(1))
       ) * 100
    ) AS pct_accepted
  , CONVERT(decimal(5,2)
      ,( CONVERT(decimal(10),SUM(sq1.mine))
       / CONVERT(decimal(10),COUNT(1))
       ) * 100
    ) AS pct_mine
  , CONVERT(decimal(5,2)
      ,( CONVERT(decimal(10),SUM(sq1.mine))
       / CONVERT(decimal(10),SUM(sq1.accepted))
       ) * 100
    ) AS pct_mine_on_accept
FROM
    sq1
GROUP BY
    sq1.UserId
  , sq1.DisplayName

Enter Parameters

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