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)
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() # count of all the rows of the database count = "select count(*) from sales1" cursor.execute(count) print ( "The count of all rows of the table :" ) print (cursor.fetchone()[ 0 ]) # Closing database connection connection.close() |
Output:
The count of all rows of the table : 4
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.