Reports median and average answer score. The MedianAnswerScore2 is more precise version of median.
Q&A for ebook publishers and readers
declare @median int; --SELECT @median = -- @median + (SELECT count(*) from Posts); SELECT @median = MAX(Score) FROM (SELECT TOP 50 percent Score FROM Posts as PU WHERE PostTypeId = 2 and CommunityOwnedDate IS NULL and PU.OwnerUserId = ##UserId## ORDER BY Score ) as t; declare @median2 int; declare @median2_below50 int; declare @median2_total int; select @median2_below50 = ( SELECT count(*) FROM (SELECT TOP 50 percent Score FROM Posts as PU WHERE PostTypeId = 2 and CommunityOwnedDate IS NULL and PU.OwnerUserId = ##UserId## ORDER BY Score ) as t WHERE Score = @median ) select @median2_total = (SELECT count(*) FROM Posts as PU WHERE PostTypeId = 2 and CommunityOwnedDate IS NULL and PU.OwnerUserId = ##UserId## and Score = @median ) /*SELECT Count(Posts.Id) AS Answers, @median AS MedianAnswerScore FROM Posts WHERE PostTypeId = 2 and CommunityOwnedDate IS NULL and OwnerUserId = ##UserId##*/ select @median + cast(@median2_below50 as DECIMAL(10,0)) / @median2_total;