Q&A for scientists using computers to solve scientific problems
SELECT TOP 10 u.id, COUNT(*) AS activity FROM Users u LEFT JOIN ( SELECT p.OwnerUserId AS user_id FROM posts p WHERE p.CreationDate >= DATEADD(YEAR, -5, GETDATE()) UNION ALL SELECT c.UserId AS user_id FROM Comments c WHERE c.CreationDate >= DATEADD(YEAR, -5, GETDATE()) ) AS user_activity ON u.id = user_activity.user_id GROUP BY u.id ORDER BY COUNT(*) DESC