正規表現の質問をしたり答えたりすることで得た、または失ったすべての評判を除いた、スタック オーバーフローの評判を知りたいと思いました(—私には「汚れたお金」のように感じます!)。
Stack Exchange のData Explorerを使用すると、これを計算できます。しかし、私はプロプライエタリ データベースと C++ ラッパー クラスを使用してプログラミングしただけだったので、自分の SQL スキルにあまり自信がありませんでした。それにもかかわらず、私はそれを試してみて、最終的に私の答えを提供するクエリを思いつきました:
-- (approximate) reputation gained/lost on a specified tag
-- only counts post upvotes and downvotes
DECLARE @UserId int = ##UserId##
DECLARE @QuestionsUp int = 0;
DECLARE @QuestionsDown int = 0;
DECLARE @AnswersUp int = 0;
DECLARE @AnswersDown int = 0;
DECLARE @Tag nvarchar(25) = 'regex';
SELECT
@QuestionsUp = COUNT(*)
FROM Tags
INNER JOIN PostTags ON PostTags.TagId = Tags.id
INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2
WHERE
Posts.OwnerUserId = @UserId and
Posts.PostTypeId = 1 and
Tags.TagName = @Tag
SELECT
@QuestionsDown = COUNT(*)
FROM Tags
INNER JOIN PostTags ON PostTags.TagId = Tags.id
INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 3
WHERE
Posts.OwnerUserId = @UserId and
Posts.PostTypeId = 1 and
Tags.TagName = @Tag
SELECT
@AnswersUp = COUNT(*)
FROM Tags
INNER JOIN PostTags ON PostTags.TagId = Tags.id
INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2
WHERE
Posts.OwnerUserId = @UserId and
Posts.PostTypeId = 2 and
Tags.TagName = @Tag
SELECT
@AnswersDown = COUNT(*)
FROM Tags
INNER JOIN PostTags ON PostTags.TagId = Tags.id
INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 3
WHERE
Posts.OwnerUserId = @UserId and
Posts.PostTypeId = 2 and
Tags.TagName = @Tag
SELECT @QuestionsUp * 5 +
@AnswersUp * 10 +
(@QuestionsDown + @AnswersDown) * -2
ただし、これは最善の方法ではありません。賛成票の質問を 5 で重み付けし、賛成票の回答を 10 で重み付けし、反対票の質問と回答を -2 で重み付けするための 4 つの個別のクエリ? このクエリを圧縮して 1 回の実行で実行する方法はありますか?
(構文、フォーマット、グッド プラクティスなどに関する補助的なアドバイスがあれば、お気軽にコメントしてください。また、タグに固有の評判を得るまたは失う他の方法がある場合は、コメントしてください。 .)