Which of my answers received more votes than the accepted answer?


Please login or register to vote for this query.

(click on this box to dismiss)

Constructed Languages

Q&A for designers and users of artificial or invented languages, consciously developed instead of having developed naturally

-- Which of my answers received more votes than the accepted answer
 DECLARE @UserId int = ##UserId##;

WITH MyScoreTable AS
  (SELECT Id AS AnswerId,
          ParentId AS QuestionId,
          Score AS MyScore
   FROM Posts
   WHERE OwnerUserId = @UserId
     AND Posts.PostTypeId = 2
     AND Posts.ParentId IN
       (SELECT Posts.Id
        FROM Posts
        WHERE Posts.AcceptedAnswerId IS NOT NULL) ),
     AcceptedAnswerTable AS
  (SELECT Score AS AcceptedScore,
          ParentId AS QuestionId,
          Id AS AnswerId
   FROM Posts
   WHERE Posts.ParentId IN
       (SELECT QuestionId
        FROM MyScoreTable)
     AND Posts.Id IN
       (SELECT DISTINCT AcceptedAnswerId
        FROM Posts) )
SELECT Posts.Id AS [Post Link],
       Posts.Score AS QuestionScore
FROM Posts
INNER JOIN MyScoreTable ON MyScoreTable.QuestionId = Posts.Id
INNER JOIN AcceptedAnswerTable ON AcceptedAnswerTable.QuestionId = Posts.Id
WHERE MyScoreTable.AnswerId <> AcceptedAnswerTable.AnswerId
  AND MyScore > AcceptedScore

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results