Questions with best answer created within 3 month range

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- Questions with most max Answer Score
-- The top 20 questions with best Answer score within 3 month range
DECLARE @From_Date DATETIME = convert(DATETIME, '##StartDate?2013/01/01##')
DECLARE @To_Date DATETIME = dateadd(mm, 3, @From_Date)

PRINT 'from ' + format(@From_Date, 'D') + ' to ' + format(@To_Date, 'D')

SELECT TOP 20 Posts.id AS [Post Link],
	users.id AS [User Link],
	Posts.CreationDate,
	Posts.Score AS [Question Score],
	max(Answer.Score) AS [max Answer Score],
	Posts.ViewCount,
	Posts.FavoriteCount
FROM Posts
INNER JOIN users
	ON Posts.OwnerUserId = users.id
LEFT JOIN Posts AS Answer
	ON Answer.parentid = Posts.id
		AND Answer.posttypeid = 2
WHERE Posts.ClosedDate IS NULL
	AND Posts.posttypeid = 1
	AND Posts.CreationDate BETWEEN @From_Date
		AND @To_Date
GROUP BY Posts.Id,
	users.id,
	Posts.CreationDate,
	Posts.Score,
	Posts.ViewCount,
	Posts.FavoriteCount
ORDER BY max(Answer.Score)  DESC

Enter Parameters

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