There already is a fine answer - but I decided to add something too. I hope at least some of this stuff might be useful.
Some issues related to the type of query you want:
- You cannot take the location field as something reliable. (E.g., I have seen many people who have fictional places there. And without additional data, you can't distinguish between Georgia in the USA and the country Georgia.)
- Location does not necessarily contain the country. For example, somebody might include only the city they're living in.
- Tags are only on questions - some extra work is needed if you want to get score from answers (or both questions and answers).
- It might be useful to restrict the query to users above certain reputation - at least if you're running it on a large site where the query might time out.
As examples I will use queries checking javascript on Stack Overflow. And I will include queries for set-theory on MathOverflow, too. (Quite often I prefer to test queries on smaller sites first - since the queries run faster. The same might be useful if you want to play around with those queries and modify them in various ways.)
Let us start with a simple approach - just checking whether the location contains the name of the country:
MathOverflow and Stack Overflow.
Some comments regarding this query:
- By changing the parameter "types" you can choose counting only questions, only answers, or both of them. (By setting this parameter to
1
or 2
or 1,2
.)
- The part
q.Id=COALESCE(p.ParentId,p.Id)
is included so that we know tags for answers, too.
As already mentioned, people can use various things in the location field. In the above example, I checked for the string "United States". So I missed people who have, for example, "USA" or "Austin, TX" as their location.
For example, if you have a look at top users in the tag javascript, maybe Kennewick, WA isn't among the places you would think about when looking for people from the USA.
Making a thorough query that checks for various possibilities is quite a lot of effort. Here are examples of such queries that somebody done for Ukraine or Canada.
I tried to modify a bit the query linked here: How can I write a query DATA.SE to list top users from all countries in the world? (This query can be used for various countries.)
This is what I ended up with: MathOverflow and Stack Overflow.
For example, I have included "Kennewick, WA" - since I knew that I want such user(s) among the results. But if I run the same query for some other tag, I can easily miss many users.
stack exchange data explorer
but I didn't find any query satisfied these conditions.tag
.