MySQL Forums
Forum List  »  Connector/Python

How to get the value of aggregate functions using MySQL Connector/Python?
Posted by: Ernest Bonat
Date: March 17, 2014 05:11PM

Sometimes we need get the value of the MySQL aggregate functions like COUNT, MAX, etc.
For example, if I need to know how many records has a table, I could write the following code:

mysql_connect = mysql.connector.connect(user=’ernest’, database=’magazine’)
sql = ‘SELECT COUNT(*) FROM author’
cursor = mysql_connect.cursor()
cursor.execute(sql)
data = cursor.fetchall()
print(data)

This will print:

[(20,)]

Two questions:

1. How to get the real 20 records value?

2. If this the correct code to get the values of the MySQL aggregate functions?

Thank you in advanced!

Ernest

Options: ReplyQuote


Subject
Written By
Posted
How to get the value of aggregate functions using MySQL Connector/Python?
March 17, 2014 05:11PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.