About
This is a SEDE query which will calculate your activity and participation on a site. It's geared for Programming Puzzles & Code Golf where questions are values more, but the values can be modified to fit general Q&A SE sites too.
Try it online!
So I did what all programmers do and I looked up how to most of this stuff on Stack Overflow and mashed the snippets from SO into my program until it worked!
Essentially this program takes input for the user's User ID and their score is calculated by::
1 * <# of Upvotes>
2 * <# of Downvotes>
10 * <# of Questions>
5 * <# of answers>
1 * <# of Comments>
The actual values of what <# of ...>
is multiplied is stored in variables which you can see I've declared.
Then within the FROM
the Upvotes, Downvotes, etc. are all counted. The outmost SELECT
is used so I can manipulate these also
Code
DECLARE @UID int = ##UserId##
DECLARE @Up int = 1
DECLARE @Down int = 2
DECLARE @Q int = 10
DECLARE @A int = 5
DECLARE @Comment int = 1
SELECT Score = Upvotes * @Up +
Downvotes * @Down +
Questions * @Q +
Answers * @A +
Comments * @Comment,
Upvotes, Downvotes, Questions, Answers, Comments
FROM (
SELECT TOP 1
(
SELECT UpVotes
From Users
WHERE Id = @UID
) as Upvotes,
(
SELECT DownVotes
From Users
WHERE Id = @UID
) as 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, Comments, Posts
) data
I'd appreciate any comments on better ways to write this program, if I can restructure this better, my formatting, and really anything because I suck at SQL.