Questions with best score created within 3 month range

0

Please login or register to vote for this query.

(click on this box to dismiss)

The top 200 questions with the most views

Science Fiction and Fantasy

Q&A for science fiction and fantasy enthusiasts

-- Questions with best score
-- The top 20 questions with best 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 Posts.score DESC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results