I was trying to use the Data Explorer for Stack Exchange to count how many votes I gave to questions and how many I gave to answers on Stack Overflow.
Looking at the schema, I've assumed you can distinguish between questions and answers basing on the ParentId. Questions have ParentId = null. This is just speculation based on the name of the fields, so if this is a wrong assumption please let me know it.
What I've done:
declare @UserId int = ##UserId## select count(*) as VotesOnQuestions from Votes join Posts on Votes.PostId = Posts.Id where UserId = @UserId and ParentId is null
The point is that, for my account, this returns a mere 44 for questions and 0 for answers, which can't be correct since I gave more than 500 votes so far. So:
- The dump for the DB is veeeeeery old
- My assumption about how to distinguish questions and answers is wrong
Bonus question: I'm completely new to Sql Server. If you need, as in this case, to return the number of elements with a null field and the number of complementary fields (all - null), how to structure the query to avoid running it twice? (bu this is probably more for Stack Overflow...)