People Helped (aka PH) (not guaranteed; work in progress)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mathematics

Q&A for people studying math at any level and professionals in related fields

DECLARE @UserId INT = ##UserId##

SELECT
  @UserId as [User Link],
  COALESCE(( SELECT
    -- sum up views of all the questions
    SUM(pp.ViewCount)
    -- `p` will be the answer
    FROM Posts p
    -- `pp` will be the question
    INNER JOIN Posts pp ON p.PostTypeId=2 AND p.ParentId=pp.Id
    -- `UserId` posted the anwwer
    WHERE p.OwnerUserId=@UserId
    AND (
      -- the answer is accepted
      pp.AcceptedAnswerId=p.Id
      -- it has score >=5
      OR p.Score>=5
      -- it carries at least 20% of sum of scores of positive-score answers
      OR p.Score*5>=( SELECT SUM(p2.Score) FROM Posts p2
        WHERE p2.PostTypeId=2 AND p2.ParentId=pp.Id AND p2.Score>0
        )
    )
  ), 0)
  +
  COALESCE(( SELECT
    -- sum up views of all the questions
    SUM(p.ViewCount)
    FROM Posts p
    -- posts by `UserId` only
    WHERE p.OwnerUserId = @UserId
      -- questions only
      AND p.PostTypeId = 1
  ), 0) AS Approximate_People_Helped

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results