Median Number of Views per Tag, for the top 30 tags

2

Please login or register to vote for this query.

(click on this box to dismiss)

Shows which tags bring in the most viewers

Moderators

Q&A for community managers, administrators, and moderators

-- Top Tags by Median ViewCount
-- See For Median http://stackoverflow.com/q/1342898/275404

SELECT TOP 30 Tags.tagName,
	MedianViews.[Median Views] AS [Median Views],
	avg(Posts.ViewCount) AS [Average Views],
	Count(*) AS [Question Count]
FROM Posts
INNER JOIN PostTags
	ON Posts.Id = PostTags.PostId
INNER JOIN Tags
	ON PostTags.TagId = Tags.Id
INNER JOIN (
	SELECT tagName,
		avg(ViewCount) AS [Median Views]
	FROM (
		SELECT Tags.tagName,
			ViewCount,
			ROW_NUMBER() OVER (
				PARTITION BY Tags.tagName ORDER BY ViewCount ASC
				) AS RowAsc,
			ROW_NUMBER() OVER (
				PARTITION BY Tags.tagName ORDER BY ViewCount DESC
				) AS RowDesc
		FROM Posts
		INNER JOIN PostTags
			ON Posts.Id = PostTags.PostId
		INNER JOIN Tags
			ON PostTags.TagId = Tags.Id
		) AS x
	WHERE RowAsc IN (
			RowDesc,
			RowDesc - 1,
			RowDesc + 1
			)
	GROUP BY tagName
	) AS MedianViews
	ON MedianViews.tagName = Tags.tagName
GROUP BY Tags.tagName, [Median Views]
having Count(*) >= 10
ORDER BY [Median Views] DESC

Enter Parameters

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