Compute a Running Total in PL/SQL

A running total is a cumulative sum of numeric columns of our given datasets. A PL/SQL is a procedural extension of SQL. We can easily write custom scripts to compute a running total. We will loop through each value of our numeric column and maintain the total of a value in a variable. We will discuss two different scenarios to implement running total:

  1. A Simple Running Total of a Column
  2. Computing Running Total Separately for each Department

Let’s set up an Environment:

To understand How to Compute a Running Total in PL/SQL we need a table on which we will perform various operations and queries. Here we will consider a table called w3wiki which contains id, name, salary, and department as Columns.

Table – w3wiki

How to Compute a Running Total in PL/SQL

Running total is a cumulative sum of a given data within a specific order. There are numerous use cases for calculating the running total. Calculating the running total helps in making predictions with the data and analyzing recent trends in data. This sometimes also helps in making a visual representation of data.

In this article, we will learn about how to compute a running total in PL/SQL where we can compute a running total with brief examples along with their respective explanations.

Similar Reads

Compute a Running Total in PL/SQL

A running total is a cumulative sum of numeric columns of our given datasets. A PL/SQL is a procedural extension of SQL. We can easily write custom scripts to compute a running total. We will loop through each value of our numeric column and maintain the total of a value in a variable. We will discuss two different scenarios to implement running total:...

Computing a Simple Running Total of Salary Column in PL/SQL

In this example, we will calculate a simple running total of salary column of ‘geeksforgeeks’ table. We will calculate and store the cumulative total by iterating through each row of our table ‘geeksforgeeks’. Lets take a look into the query for more clear understanding....

Computing Running Total Separately for Each Department in PL/SQL

In this example, we will calculate the running total of salary column but this time we will compute running total for different departments separately. Let us refer to the query block for more clear understanding....

Conclusion

Overall, running total is a cumulative sum of a numeric columns of a given dataset. Computing a running total can help us understand the trends of our given dataset. We can also analyze and make predictions. It sometimes also helps in calculating and making visual representation. We have covered on how to calculate running total for a numeric column as well as how we can calculate it by separating it over some specific departments/categories. Now you have a good understanding on computing a running total and you can write queries related to it and can get the desired output....

Contact Us