I needed to practice writing a “running totals” t-sql query with SQL Server. The first thing I did was create an example database called “Running Totals,” and then a couple tables.
Create the Running Totals database.
Create a couple tables “Customers” with 250 rows and “Orders” with 100 randon rows with datetime stamp.
Once the database and tables are created and the tables are populated with test data, you can practice writing Running Totals queries. Below is what worked for me. I am sure there are many ways to write this query.