Hello,
You could use the Reporting API to run a report that would give you incidents by server, and then in your script that calls the API, you could count the incidents in the report. Or, you could query the database directly. However, we don't publish the schema as we consider it Intellectual Property. You might be able to find the tables in the DB that correlate to the information you are looking for, but you would need to find those on your own. If you really need a SQL solution for this, you would need to contact Professional Services to assist you.
What is the end goal of your program/script for collecting this information? Perhaps there is another way to get your answer?
I hope this helps.
Best,
Ryan