You should not run your own SQL queries against the SharePoint database for multiple reasons. According to Microsoft:
Direct modification of the SharePoint database or its data is not recommended because it puts the environment in an unsupported state.
If a server component requires information from the database, it must get that data by using the appropriate items in the SharePoint object model, and not by trying to get the items from the data structures in the database through some query mechanism.
A Powershell script run from a web front end server is probably the simplest option for a one-time report. I recommend asking a new question if you need help with the syntax or specifics of running a Powershell script to query SharePoint.