Q&A about the site for musicians, students, and enthusiasts
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 Select id from users where id='-1'