Quantcast
Channel: MySQL Forums - Connector/Python
Viewing all articles
Browse latest Browse all 384

How to get the value of aggregate functions using MySQL Connector/Python? (2 replies)

$
0
0
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

Viewing all articles
Browse latest Browse all 384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>