I would like to know how to use the count function when using sqlite in python to look up and return the number of specific values there are in a table. For example, I want to be able to look in an sqlite table showing students and their characteristics and be able to find how many of them are male or female using python. I have done some research but have only found relevant information for when you are just using sqlite.
Did you try this :
rowsQuery = "SELECT Count() FROM %s" % table
cursor.execute(rowsQuery)
numberOfRows = cursor.fetchone()[0]
you have to change the rowsQuery according to your need .
For your question:
rowsQuery = "select count(STUDENT) from table_name where Gender= 'Male'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With