AboutThis 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 alsoCodeDECLARE @UID int = ##UserId##DECLARE @Up      int = 1DECLARE @Down    int = 2DECLARE @Q       int = 10DECLARE @A       int = 5DECLARE @Comment int = 1SELECT Score = Upvotes   * @Up +          Downvotes * @Down +          Questions * @Q +          Answers   * @A +          Comments  * @Comment,       Upvotes, Downvotes, Questions, Answers, CommentsFROM (  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) dataI'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.
Stack Exchange User Activity Score
beginner;sql;stackexchange;t sql
TOP 1When selecting values that correspond to Unique fields referenced by constants (OwnerUserId), you're only really selecting one field, meaning this is redundant.UVNUnexplained Variable NamesDon't use names like Q and A, they're confusing at best and unreadable at worst.DECLARE @QDECLARE @ADECLARE @QuestionsDECLARE @AnswersYo dawg, heard you like SELECTsSELECT --...FROM (  SELECT TOP 1    (      SELECT UpVotes      From Users      WHERE Id = @UID    ) as Upvotes,SQL is not intended to be used like that.You don't need to create pseudo tables to select from to store your data.You can use a base table, and then specify certain fields calling other tables from that.SELECT  UpVotes + DownVotes as [Total Votes],  (SELECT COUNT(*) FROM Posts WHERE OwnerUserId = Users.Id) as [Post Count]FROM UsersFormattingThis formatting is a bit weird:SELECT Score = Upvotes   * @Up +          Downvotes * @Down +          Questions * @Q +          Answers   * @A +          Comments  * @Comment,You might want to break these up a little more.NamingThese aren't the actual values, they're type weights, so I'd add the word weight to the end of the variable names:DECLARE @Up      int = 1DECLARE @Down    int = 2DECLARE @Q       int = 10DECLARE @A       int = 5DECLARE @Comment int = 1Into:DECLARE @UpVotesWeight     int = 1DECLARE @DownVotesWeight   int = 2DECLARE @QuestionsWeight   int = 10DECLARE @AnswersWeight     int = 5DECLARE @CommentsWeight    int = 1