Has own-answer, bountied another answer and accepted a third one

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT Q.Id AS [Post Link]
FROM
  Posts Q,
  Posts OwnAnswer,
  Posts BountyAnswer,
  Posts AcceptedAnswer,
  Votes BountyStart,
  Votes BountyClose
WHERE
  -- binding conditions
  OwnAnswer.ParentId = Q.Id
  AND
  BountyAnswer.ParentId = Q.Id
  AND
  Q.AcceptedAnswerId = AcceptedAnswer.Id
  AND
  BountyStart.PostId = Q.Id
  AND
  BountyClose.PostId = BountyAnswer.Id
  AND
  OwnAnswer.OwnerUserId = Q.OwnerUserId
  AND
  -- all posts need to have a registered user
  Q.OwnerUserId > 0
  AND
  OwnAnswer.OwnerUserId > 0
  AND
  BountyAnswer.OwnerUserId > 0
  AND
  AcceptedAnswer.OwnerUserId > 0
  AND
  -- question + ownanswer, acceptedanswer, and bountiedanswer must have
  -- different owners
  Q.OwnerUserId = OwnAnswer.OwnerUserId
  AND
  AcceptedAnswer.OwnerUserId != Q.OwnerUserId
  AND
  Q.OwnerUserId != BountyAnswer.OwnerUserId
  AND
  BountyAnswer.OwnerUserId != AcceptedAnswer.OwnerUserId
  AND
  BountyStart.UserId = Q.OwnerUserId
  AND
  BountyStart.VoteTypeId = 8
  AND
  BountyClose.VoteTypeId = 9
  -- none of them is community-owned
  AND
  Q.CommunityOwnedDate IS NULL
  AND
  BountyAnswer.CommunityOwnedDate IS NULL
  AND
  AcceptedAnswer.CommunityOwnedDate IS NULL
  AND
  OwnAnswer.CommunityOwnedDate IS NULL
  -- question has exactly 3 answers
  AND
  Q.AnswerCount = 3
ORDER BY Q.Id DESC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results