SQL Tip: Running Totals with Multiple Joins

Here’s one for the geeks.

I had need to collect a running total in SQL. There are plenty of good examples for how to do this when the records are in a single table. But there were few examples (that I could find) for how to do this involving joins on multiple tables. In my case, the table structure (simplified, using MySQL) is as follows:

Multiple Tables

(Click for larger image.)

The output I wanted was as follows:

The SQL that accomplishes this:

Hope this is helpful to someone.