English

Sartaj has created a table named Student in MYSQL database, SCHOOL: rno(Roll number )- integer name(Name) - string DOB (Date of birth) – Date

Advertisements
Advertisements

Question

Sartaj has created a table named Student in MYSQL database, SCHOOL:

  • rno(Roll number )- integer
  • name(Name) - string
  • DOB (Date of birth) – Date
  • Fee – float

Note the following to establish connectivity between Python and MySQL:

  • Username - root
  • Password - tiger
  • Host - localhost

Sartaj, now wants to display the records of students whose fee is more than 5000. Help Sartaj to write the program in Python.

Short/Brief Note
Advertisements

Solution

import mysql.connector as mysql
con1 = mysql.connect (host="localhost", user="root", password="tiger", database="sample2023")
mycursor=con1.cursor()
query = "SELECT * FROM student where fee>{}".format (5000)
mycursor.execute(query)
data=mycoursor.fetchall()
for rec in data:
print (rec)
con1.close()
shaalaa.com
Data Types and Constraints in MySQL
  Is there an error in this question or solution?
2023-2024 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×