fork download
  1. import mysql.connector
  2. mycon = mysql.connector.connect(
  3. host='localhost',
  4. user='root',
  5. password='password',
  6. database='School')
  7. if mycon.is_connected():
  8. print('Database connected')
  9. cursor = mycon.cursor()
  10. sql ='SELECT Stream, COUNT(*) FROM STUDENT GROUP BY Stream'
  11. cursor.execute(sql)
  12. data = cursor.fetchall()
  13. print("Answer is:")
  14. for rec in data:
  15. print(rec)
Success #stdin #stdout 0.03s 26024KB
stdin
Standard input is empty
stdout
import mysql.connector
mycon = mysql.connector.connect( 
    host='localhost', 
    user='root',
    password='password',
    database='School')
if mycon.is_connected():
   print('Database connected')
cursor = mycon.cursor()
sql ='SELECT Stream, COUNT(*) FROM STUDENT GROUP BY Stream'
cursor.execute(sql)
data = cursor.fetchall()
print("Answer is:")
for rec in data:
    print(rec)