I'm trying to write a simple query in Data Explorer to find out the number of answers a user has for a certain tag. Here's what I have so far (also here):
SELECT Count(*)
FROM Users u
JOIN Posts p ON p.owneruserid = u.id
JOIN PostTags pt ON pt.PostId = p.Id
JOIN Tags t ON t.Id = pt.TagId
WHERE u.Id = ##UserId##
AND t.TagName IN
(
##Tag1:string##
)
The problem is that this is only returning posts that are questions. I've tried modifying the WHERE clause to:
WHERE u.ID = ##UserId## AND p.postTypeId = 2 ...
To only return posts that are answers, but it returns a count of 0, which is leading me to believe that my JOINs are only resulting in posts that are questions. Can anyone see why this is happening, and how to modify this query to show answers as well?
FYI the ultimate goal is to try to see how many more answers are needed for a tag bronze/silver/gold badge.
It seems that tags are not added to answers, so you should check tags on question:
SELECT Count(*)
FROM Users u
JOIN Posts p ON p.owneruserid = u.id
JOIN Posts q ON q.Id = p.ParentId
JOIN PostTags pt ON pt.PostId = q.Id
JOIN Tags t ON t.Id = pt.TagId
WHERE u.Id = ##UserId## AND t.TagName IN (##Tag1:string##)