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()
# Count the number of records in each stream and display it:
sql ='SELECT Stream, COUNT(*) FROM STUDENT GROUP BY
Stream'
cursor.execute(sql)
data = cursor.fetchall()
print("Answer for a):")
for rec in data:
print(rec)
# Display the number of students who have secured 'A' Grade:
sql ="SELECT COUNT(*) FROM STUDENT WHERE Grade='A'"
cursor.execute(sql)
count = cursor.fetchone()[0]
print("The number of students with 'A' grade is {count}")
# Add a new column called Rank in the table:
sql ='ALTER TABLE STUDENT ADD Rank CHAR(3)'
cursor.execute(sql)
mycon.commit()
print('Field Added')
mycon.close()