I created this query back in January to find the top active answerers on Code Review and thought that it might be a good idea to get other opinions on my SQL coding using a database that we can all access.
This will probably be the first of several queries that I post for review.
Actual SEDE Query --> Top Active Answerers on site
--@DaysSinceActivity is the amount of days that you would like to scan for activity --@NumberOfUsers is the number of users you want to return. DECLARE @DaysSinceActivity INT = ##DaysSinceActivity## SELECT TOP ##NumberOfUsers## Users.Id as [User Link], Count(Posts.Id) AS Answers, CAST(AVG(CAST(Score AS float)) as numeric(6,2)) AS [Average Answer Score] FROM Posts INNER JOIN Users ON Users.Id = OwnerUserId WHERE PostTypeId = 2 and CommunityOwnedDate is null and ClosedDate is null AND Users.LastAccessDate > DateAdd(Day, -31, GetDate()) GROUP BY Users.Id, DisplayName HAVING Count(Posts.Id) > 10 ORDER BY [Average Answer Score] DESC