VOOZH about

URL: https://www.geeksforgeeks.org/python/using-sqlite-aggregate-functions-in-python/

⇱ Using SQLite Aggregate functions in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Using SQLite Aggregate functions in Python

Last Updated : 7 Feb, 2022

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.

👁 Image

Max() function

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

Syntax: max(name_of_the_column)

Output:

The maximum yearly sale is is:
98787.0

Min() function 

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

Syntax: min(name_of_the_column)

Output:

The minimum yearly sale is:
25659.0

Avg() 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.

Syntax: avg(name_of_the_column)

Output:

The average yearly sales is:
(66441.75,)

Total() function 

total() function returns the total or sum of all values of the column.

Syntax: total(name_of_the_column)

Output:

The total monthly sale of all items is:
26230.0

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)

Output:

The sum of yearly sale is :
265767.0

Count() function

count() function returns the number of nonnull values in a specific column or the whole table.

count of all rows in a table:

count(*)

count of all rows in a specified column:

count(name_of_the_column)

Output:

The count of all rows of the table :
4
Comment
Article Tags:
Article Tags: