Number of 'favorite votes' each user has cast

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

--SELECT u.Id AS [User Link], COUNT(p.Id) AS 'Total Votes', --COUNT(IIF(v.VoteTypeId = 5, 1, 0)) AS 'Favorites Count',
--(SELECT COUNT(v1.Id) FROM Votes v1 WHERE v1.UserId = u.Id GROUP BY v1.UserId) AS 'Count'
--COUNT(IIF(v.Id IS NULL, 0, 1)) AS 'Count',

SELECT u.Id AS [User Link], --COUNT(IIF(v.VoteTypeId = 5, 1, 0)) AS 'Favorites Marked',
'site://users/' + CAST(u.Id AS nvarchar(10)) + '?tab=favorites' AS 'User Favorites Page'


FROM Users u
--LEFT JOIN Votes v ON v.UserId = u.Id
--JOIN Posts p ON v.PostId = p.Id


--WHERE v.VoteTypeId IS NULL --OR v.VoteTypeId = 5

WHERE (SELECT COUNT(v.UserId) FROM Votes v WHERE v.UserId = u.Id) IS NULL


--GROUP BY u.Id

--ORDER BY COUNT(IIF(v.VoteTypeId IS NULL, 0, 1)) ASC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results