나는 제외한 내 스택 오버플로 명성을 알고 싶어 모든 명성 regex 질문 질문과 답변에서 얻은 또는 손실 (나에게 그것은 "더러운 돈"같은 느낌 —를!)WHERE 표현식을 기반으로 가중치 가중 합을 계산하는 방법이 있습니까?
스택 교환의 Data Explorer 나를 계산할 수 것 이. 그러나 독점적 인 데이터베이스와 C++ 래퍼 클래스를 사용하여 프로그래밍 만 했으므로 SQL 기술에 대한 자신감이 부족했습니다. 그럼에도 불구하고, 나는 그것에게 기회를주고, 결국 a query that provided my answer 함께했다 : 이것은하지만, 할 수있는 최선의 하나가 될 수 없습니다
-- (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
. 4 개의 개별 쿼리로 인해 5 개의 질문이 upvoted, 10 개의 답변이 upvoted, -2로 질문 및 답변이 downvoted됩니까? 이 쿼리를 한 번에 실행하도록 압축하는 방법이 있습니까?
(구문, 형식, 우수 사례 등에 관한 조언이 있으면 언제든지 의견을 말하십시오.) 평판을 얻거나 잃는 다른 방법이 있으면 의견을 말하십시오. — 태그에만 해당 — 나는 천국입니다. 't은에 고려)
오, 좋은! QuestionsUp, QuestionsDown, AnswersUp, AnswersDown 변수를 모두 없애고 SELECT 내에서 전체 계산을 수행 할 수있는 방법이 있습니까? (나는 결국 가중 점수의 합이 필요합니다.) 'THEN 1'을 각각의 점수 (5, -2, 10, -2)로 바꾸고 모든 타겟을 단일 변수 — 결과가없는 4 열 (모두 단일 변수의 이름 포함) 만 반환되었습니다. –