Question 2

0

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

SELECT TOP 10 
    Users.Id, 
    Users.DisplayName, 
    PostCounts.PostCount + CommentCounts.CommentCount AS PostsAndComments
FROM Users
LEFT JOIN (
    SELECT OwnerUserId, COUNT(*) AS PostCount
    FROM Posts
    WHERE CreationDate >= DATEADD(YEAR, -5, GETDATE())
    GROUP BY OwnerUserId
) AS PostCounts ON Users.Id = PostCounts.OwnerUserId
LEFT JOIN (
    SELECT UserId, COUNT(*) AS CommentCount
    FROM Comments
    WHERE CreationDate >= DATEADD(YEAR, -5, GETDATE())
    GROUP BY UserId
) AS CommentCounts ON Users.Id = CommentCounts.UserId
ORDER BY PostsAndComments DESC;

Enter Parameters

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