I am trying to efficiently use the SEDE tool to get a list of tags a user has answered questions on, and their stats on each Tag.
My code works for my account in 3185 ms, but if I try to run it on @jon-skeet's, user ID (22656) then it times out.
Are there ways to make this more efficient / better code, and allow it to be used for any user ID?
-- The tags and scores of my posts
CREATE TABLE #MyPosts (
_tags nvarchar(250) COLLATE SQL_Latin1_General_CP1_CS_AS,
_score int
);
INSERT INTO #MyPosts
SELECT
Question.Tags,
Answers.Score
FROM
Posts as Answers
INNER JOIN
Posts AS Question
ON
Question.Id = Answers.ParentId
WHERE
Answers.PostTypeId = 2 AND
Answers.OwnerUserId = ##UserId:int?8041461##;
--------------------------------------------------------------------------
-- All of the tags with the total score and the amount of times used
CREATE TABLE #TagCounts (
_tagName nvarchar(35) COLLATE SQL_Latin1_General_CP1_CS_AS,
_score int,
_count int
);
INSERT INTO #TagCounts
SELECT
Tags.TagName,
sum(_score),
count(*)
FROM
#MyPosts
INNER JOIN Tags ON #MyPosts._tags LIKE '%<'+Tags.TagName +'>%'
GROUP BY Tags.Id,Tags.TagName;
--------------------------------------------------------------------------
-- Outputs the tags with links, total score, count and average score
SELECT
_tagName as [TagName],
_score as 'Total Score',
_count as 'Answer Count',
cast(_score as FLOAT) / _count as 'Average Score'
FROM
#TagCounts
WHERE
_score IS NOT NULL
ORDER BY
_score DESC