I am querying the Stack Exchange Database at https://data.stackexchange.com/stackoverflow/query/new
to count the total number of posts that have the same AnswerCount
value as another post.
This is my attempt which causes an error Something unexpected went wrong while running your query. Don't worry, blame is already being assigned.
The idea is to increase the counter after a post/record in the Posts
table has a single match for its AnswerCount
value with another post/record, while not counting the match with its own AnswerCount
value.
Select Count(*)
From Posts as p1
Join Posts as p2
On p2.Id = {
Select Top 1 Id
From p2
Where p1.AnswerCount = p2.AnswerCount
And p1.Id <> p2.Id
};
This is Stack Exchange post I am using as a reference: How to Join to first row