![]() |
VOOZH | about |
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.
👁 Imagemax() 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 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 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 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 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 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