Q&A for people interested in the history and origins of science and mathematics
-- What is the average answer's (reputation / popularity) ratio for a given user ? DECLARE @UserId int = ##UserId## SELECT COUNT(a.id) AS Answers, SUM(CASE WHEN q.AcceptedAnswerId = a.Id THEN 1 ELSE 0 END) AS Accepted, SUM(a.Score) AS Score, SUM(q.ViewCount) AS Views, ROUND(SUM( (CAST(a.Score AS float) / CAST(q.ViewCount AS float)) * 100) / COUNT(a.id), 3) as [Average Ratio] FROM Posts a INNER JOIN Posts q ON q.Id = a.ParentId WHERE a.PostTypeId = 2 AND a.OwnerUserId = @UserId