Sum() function

sum() function returns the sum of all values of the column, in case all values are null , it returns null. so, total() function is a comparatively better function.

Syntax: sum(name_of_the_column)

Python3




# import the sqlite module
import sqlite3
  
# establishing a connection to the database
connection   = sqlite3.connect("sales.db")
  
# creating a cursor object
cursor = connection.cursor()
  
# sum of all the yearly sale
sum_yearly_sale = "select sum(yearly_sale) from sales1"
  
cursor.execute(sum_yearly_sale)
  
# Print the sum of scores
print("The sum of yearly sale is :")
  
print(cursor.fetchone()[0])
  
# Closing database connection
connection.close()


Output:

The sum of yearly sale is :
265767.0

Using SQLite Aggregate functions in Python

In this article, we are going to see how to use the aggregate function in SQLite Python. An aggregate function is a database management function that groups the values of numerous rows into a single summary value. Average (i.e., arithmetic mean), sum, max, min, Count are common aggregation functions. SQLite provides us with many aggregate functions used for statistical analysis. 

Database for demonstration: To download the database click here.

Similar Reads

Max() function

max() function returns the maximum value of all the values from the column we specified....

Min() function

...

Avg() function

min() function returns the minimum value of the all the values from the column we specified....

Total() function

...

Sum() function

avg() function returns the average or arithmetic mean of all the values in the column we specify. If any null value is there in the column it’s left out....

Count() function

...