Total View Count of User's Accepted Answers

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

SELECT 'Grand Total' AS Title, SUM(Question.ViewCount) AS ViewCount, SUM(Answer.Score) AS Score

FROM Posts AS Answer
  INNER JOIN PostTypes ON PostTypes.Id = Answer.PostTypeId
  INNER JOIN Posts AS Question ON Question.Id = Answer.ParentId AND
    Question.AcceptedAnswerId = Answer.Id

WHERE
  PostTypes.Name = 'Answer' AND
  Answer.OwnerUserId = ##UserId## AND
  Answer.CommunityOwnedDate IS NULL

UNION ALL

SELECT
  Question.Title, Question.ViewCount, Question.Score

FROM Posts AS Answer
  INNER JOIN PostTypes ON PostTypes.Id = Answer.PostTypeId
  INNER JOIN Posts AS Question ON Question.Id = Answer.ParentId AND
    Question.AcceptedAnswerId = Answer.Id

WHERE
  PostTypes.Name = 'Answer' AND
  Answer.OwnerUserId = ##UserId## AND
  Answer.CommunityOwnedDate IS NULL
  
ORDER BY
  ViewCount DESC

Enter Parameters

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