For the case of exporting data for use by a statistical package for analysis, I would recommend using the Views module in conjunction with Views Data Export.
Views will allow you to to create custom queries over your database, configured fully through the UI. Views Data Export can take a View, and present it as CSV, XLS, or XML for consumption by another tool.
Directly querying a Drupal database from the outside is not an easy task, and is not recommended; the schema can vary as configuration changes. In some cases, it is possible to get the raw SQL that a View is using, and copy that to another tool. However, certain types of Views will not get all of the data as a single query.