Votes Per Questions

1

Please login or register to vote for this query.

(click on this box to dismiss)

This query counts the number of up-votes/down-votes casted for all the questions.

Drupal Answers

Q&A for Drupal developers and administrators

DECLARE @Questions Int
DECLARE @Votes Int
DECLARE @WithoutVotes Int

SELECT @Votes = COUNT(*) FROM Votes v INNER JOIN Posts p ON p.Id = v.PostId
WHERE v.VoteTypeId IN (2, 3) AND p.ParentId IS NULL
  
SELECT @Questions = COUNT(*) FROM Posts p
WHERE p.ParentId IS NULL

SELECT @WithoutVotes = COUNT(*) FROM Posts p
WHERE p.ParentId IS NULL AND
  p.Id NOT IN (SELECT v.PostId FROM Votes v WHERE v.VoteTypeId IN (2, 3))

SELECT @Questions AS [Questions],
  @WithoutVotes AS [Questions without votes],
  @Votes AS [Votes]

Enter Parameters

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