Question 2

0

Please login or register to vote for this query.

(click on this box to dismiss)

Software Engineering

Q&A for professionals, academics, and students working within the systems development life cycle

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 meta site
loading Hold tight while we fetch your results