Q&A for people studying math at any level and professionals in related fields
WITH Upvoted AS ( SELECT p.Id, COUNT(*) AS Upvotes FROM Posts p INNER JOIN Votes ON p.Id = Votes.PostId WHERE Votes.VoteTypeId = 2 -- upvotes GROUP BY p.Id ) SELECT u.Id AS UserId, u.DisplayName, COUNT(p.Id) AS TotalPosts, SUM(v.Upvotes) AS TotalUpvotes FROM Posts p INNER JOIN Users u ON p.OwnerUserId = u.Id INNER JOIN Upvoted v ON p.Id = v.Id GROUP BY u.Id, u.DisplayName ORDER BY u.Id;