Activity Score

0

Please login or register to vote for this query.

(click on this box to dismiss)

Code Golf and Coding Challenges

Q&A for programming puzzle enthusiasts and code golfers

DECLARE @UID int = ##UserId##

DECLARE @Up      int = 5
DECLARE @Down    int = 8
DECLARE @Q       int = 25
DECLARE @A       int = 10
DECLARE @Comment int = 5

SELECT Score = Upvotes   * @Up +
          Downvotes * @Down +
          Questions * @Q +
          Answers   * @A +
          Comments  * @Comment,
       Upvotes, Downvotes, Questions, Answers, Comments
FROM (
  SELECT Upvotes, Downvotes,
    (
      SELECT COUNT(*)
      FROM Posts
      WHERE OwnerUserId = @UID and PostTypeId = 1
    ) as Questions,
    (
      SELECT COUNT(*)
      FROM Posts
      WHERE OwnerUserId = @UID and PostTypeId = 2
    ) as Answers,
    (
      SELECT COUNT(*)
      FROM Comments
      WHERE UserId = @UID
    ) as Comments
  FROM Users
  WHERE Id = @UID
) data

Enter Parameters

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