मराठी

The code given below reads the following records from the table employee and displays only those records that have employees coming from the city 'Delhi':

Advertisements
Advertisements

प्रश्न

The code given below reads the following records from the table employee and displays only those records that have employees coming from the city 'Delhi':

E_code - String
E_name - String
Sal - Integer
City - String

Note the following to establish connectivity between Python and MySQL:

  • Username is root
  • Password is root
  • The table exists in a MySQL database named emp.
  • The details (E_code,E_name,Sal,City) are the attributes of the table.

Write the following statements to complete the code:

Statement 1 - to import the desired library.

Statement 2 - to execute the query that fetches records of the employees/coming from the city ‘Delhi’.

Statement 3 - to read the complete data of the query (rows whose city is Delhi) into the object named details, from the table employee in the database.

import ____________ as mysql  #Statement 1
def display():
   mydb=mysql.connect(host="localhost",user="root"
   passwd="root", database=" emp")
   mycursor=mydb.cursor()
   ____________ #Statement 2
   details = ____________ # Statement 3
   for i in details:
       print (i)
कोड लेखन
Advertisements

उत्तर

Statement1: mysql.connector
Statement2: mycursor.execute("Select * from emp where city='Delhi'”)
Statement3: mycursor.fetachall()
shaalaa.com
SQL for Data Query
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2022-2023 (March) Set 4

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×