The SUM function in SQL is used to calculate the total values in a specific column of a table.
The basic syntax is:
To exemplify how to use the SUM SQL, suppose you have a bookshop table with a price column. The total amount for all books can be calculated with the following SQL query:
If you want to sum only the Classic books, you could use a WHERE clause in a statement like this:
genre = 'Classic';
In each of these examples, the SUM SQL function is used to calculate the totality of the values in a specific column of a table. The query’s result is a single value representing the sum of all the values in the column.
SQL SUM in Coginiti
Coginiti allows you to apply the aggregation functionality to any column by dragging and dropping the values you want to sum.
Here’s an example of how you can sum rows in Coginiti Grid:
- Open the Grid View
- Click “Columns’”
- Drag and drop the values you want to sum.
Note that when you drag and drop a column to “Values,” it will come with the last aggregation function used. Click on it to change and scroll to find the aggregate function you want.