Accepted rate of user (both question and 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

DECLARE @UserID Int = ##UserID?9449426##

DECLARE @QAccepted Int
DECLARE @QUnaccepted Int
DECLARE @QTotal Int

DECLARE @AAccepted Int
DECLARE @AUnaccepted Int
DECLARE @ATotal Int

SELECT
  @QAccepted =   SUM(IIF(AcceptedAnswerId IS NOT NULL, 1, 0)),
  @QUnaccepted = SUM(IIF(AcceptedAnswerId IS NULL    , 1, 0)),
  @QTotal =      COUNT(*)
FROM Posts
WHERE OwnerUserId = @UserID AND PostTypeId = 1

SELECT
  @AAccepted =   SUM(IIF(q.AcceptedAnswerId IS NOT NULL, 1, 0)),
  @AUnaccepted = SUM(IIF(q.AcceptedAnswerId IS NULL    , 1, 0)),
  @ATotal =      COUNT(*)
FROM Posts a
LEFT JOIN Posts q ON a.ParentId = q.Id
WHERE a.OwnerUserId = @UserID AND a.PostTypeId = 2

SELECT
  @QAccepted Q_Accepted,
  @QUnaccepted Q_Unaccepted,
  @QTotal Q_Total,
  1.0 * @QAccepted / @QTotal Q_AcceptedRate,
  @AAccepted A_Accepted,
  @AUnaccepted A_Unaccepted,
  @ATotal A_Total,
  1.0 * @AAccepted / @ATotal A_AcceptedRate

Enter Parameters

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