TagPercentage calculators for Developer Story

1

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

DECLARE @TagId INT = (
  SELECT Id FROM Tags WHERE LOWER(TagName)=LOWER(##TagName:string##)
);

WITH U AS (
  SELECT Posts.OwnerUserId AS UserId, SUM(Posts.Score) AS TagScore
  FROM PostTags, Posts
  WHERE
    PostTags.TagId = @TagId
    AND
    Posts.ParentId = PostTags.PostId
    AND
    Posts.CommunityOwnedDate IS NULL
  GROUP BY Posts.OwnerUserId
  HAVING COUNT(*) > 1 --AND SUM(Posts.Score) >= 0
),
ScoresRaw AS (
  SELECT TagScore, COUNT(*) AS Count
  FROM U
  GROUP BY TagScore
)
SELECT
  TagScore,
  Count,
  SUM(Count) OVER (ORDER BY TagScore DESC) AS CumCount,
  100.0 * SUM(Count) OVER (ORDER BY TagScore DESC)
    / (SELECT COUNT(*) FROM U) AS Pct
FROM ScoresRaw
ORDER BY TagScore DESC

Enter Parameters

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