from dbconfig import * import pymysql import sys #Â Use the school code in command line arguments #Â to list all students majoring in a department #Â in the school. #Â [1] Making connection to the MySQL server db = get_mysql_param() cnx = pymysql.connect(user=db['user'], password=db['password'], host=db['host'], database=db['database'], port=int(db['port'])) cursor = cnx.cursor() #Â [2] Prepare a SQL query for the problem query = ''' SELECT CONCAT (s.fname, ' ', s.lname) AS student, d.deptName, CONCAT(f.fname, ' ', f.lname) as advisor FROM student AS s LEFT JOIN department AS d ON (s.major = d.deptCode) LEFT JOIN faculty AS f ON (s.advisor = f.facId) WHERE d.schoolCode = %s; ''' #Â [2b] Get input values school_code = 'CSE' if len(sys.argv) > 1: school_code = sys.argv[1] #Â Execute the query cursor.execute(query, school_code) #Â [3] Use the result in the query for (student, major, advisor) in cursor: print(f"{student}: major={major}; advisor={advisor}") #Â [4] Housekeeping cursor.close() cnx.close()