4

If I type the following in the search bar:

answers:3 is:question [stata]

I get back all questions in with three or more answers.

Is there a way to identify the questions in a particular tag with the most and/or least answers?

Bonus points if the results are also ordered.

The least number of answers can be either one or zero. Ideally an answer should cover both.

5
  • try doing a big number then reducing by one each time you click search May 22, 2018 at 12:07
  • 2
    Please be clearer about 'the least'. Shouldn't questions with no answers win that category?
    – Martijn Pieters Mod
    May 22, 2018 at 12:07
  • 13
    Summons rene wait until magic happens
    – kayess
    May 22, 2018 at 12:07
  • 3
    @kayess: surely anyone can write select question.id as [Post Link], question.score, count(answer.id) as [# answers] from posts as question outer join posts as answer on question.id = answer.parentid where question.tags like '%<##tagname##>%' group by question.id, question.score order by count(answer.id) desc? :-P
    – Martijn Pieters Mod
    May 22, 2018 at 12:10
  • 2
    I downvoted because I think the post isn't useful as its very unlikely a search like this would ever be neede May 22, 2018 at 12:11

1 Answer 1

8

You can use the Stack Exchange Data Explorer to run queries against a recent copy of the database; this is great for running more complex searches.

I've written up a query that orders questions by the number of answers, given a tag:

select question.id as [Post Link], question.score, question.answercount
from posts as question 
inner join posttags on posttags.postid = question.id
inner join tags on tags.id = posttags.tagid 
where tags.tagname = '##tagname##'
order by question.answercount desc

This includes questions with no answers; if you want to limit it to questions with at least one answer add a and question.answercount > 0 clause before the order by clause.

You can take a look a the results for the stata tag.

Personally, I don't think this kind of search is all that interesting. The number of answers to a post doesn't vary all that much, and questions with no or just one answer vastly outnumber posts with more answers:

Answers per question histogram for the stata tag

5
  • 3
    Many thanks. I personally find this quite useful and i also learned something new as i had no idea that there is a Data Explorer.
    – user8682794
    May 22, 2018 at 12:27
  • 2
    Uuuhmmm, answercount is an attiribute of posts. and that like on tags gives you a full-table scan on a not so small table. Consider this instead: data.stackexchange.com/stackoverflow/query/854732
    – rene
    May 22, 2018 at 16:05
  • @rene: facepalm. Indeed, I'll adjust.
    – Martijn Pieters Mod
    May 22, 2018 at 17:53
  • 3
    @PearlySpencer you might like the tutorial.
    – rene
    May 22, 2018 at 19:01
  • 3
    @rene Thank you, this is very helpful indeed. Stack Exchange Data Explorer was a really exciting discovery today!
    – user8682794
    May 22, 2018 at 19:05

You must log in to answer this question.