
column_I_want_to_sum
- this is the column with the values you want to add upcolumn_I_want_to_order_by
- this is the column you want to order your running total overoptional_other_column_I_want_to_order_by
- this column is optional and you can add as many moreorder by
columns as you need. For your running total to only go up an increment of one row, you’ll need to add every dimension in your results table to theORDER BY
bit in your SQL. And, the order of these will need to be the same as the ordering you’ve added to the columns in your results table.
Here’s the SQL you can copy-paste to calculate a running total
💎 Level up your SQL:
- You can specify if you want to order your columns in ascending order (1, 2, 3, 4) or descending order (4, 3, 2, 1) using the key words
ASC
andDESC
in yourORDER BY
clause. By default, a column will be ordered in ascending order - so if you want it ordered ascending, you don’t need to add anything.