Not specifically a single tutorial that walks you through a task, but I can give you references to related elements which hopefully you can string together to accomplish your goal. It may be more challenging than a walk through, but I think you’ll also learn more in the process.
Part of the solution depend on what sort of data you need from the DB. To get WP posts of some sort, such as a media attachment, you can use the WP_Query class. You should find the examples and user notes near the end helpful.
If you need data from a non-WP table, but within the WP database, you would use that global $wpdb object I mentioned, whose purpose you grasped exactly. The global variable $wpdb
contains an instance a wpdb class object. The global object has already connected to the DB when WP was initialized. You can use its class methods to make various DB queries. wpdb::get_var() is a pretty useful method. Or use wpdb::query() to execute any MySQL query you may wish to execute.
One way to execute PHP code and have results appear on a page is to create a custom page template to contain your code. You might prefer the subsequent section on templates for one specific page.
You should look over the entire theme handbook into which I’ve linked just to learn what other information is available, some of it will be useful at one point or another. It may not be necessary for this particular task, but also look over the Plugin Handbook to see the sort of information offered.
You shouldn’t save your template with a distributed theme, it’ll be lost when the theme updates, you should create a child theme to contain your custom work.
Finally, developing on a hosted site is kind of a pain. Most developers prefer to work on a localhost installation. Being saved from the cycle of upload/download of files may not seem like a much of an advantage, but being saved from doing so dozens of times starts to add up.