import pymysql.cursors
#实例化
connection = pymysql.connect(host='localhost',
port=3306,
user='root',
password='123456',
db='教育',
charset='utf8',
cursorclass = pymysql.cursors.DictCursor)
#光标
try:
cursor = connection.cursor()
sql = """
SELECT *
from 5_chengji c
JOIN 2_student_info s ON c.mes_StudentID = s.bf_StudentID
JOIN 6_exam_type e ON c.exam_type = e.EXAM_KIND_ID
JOIN 1_teacher t on s.cla_id = t.cla_id
LIMIT 0,100
"""
cursor.execute(sql)
result = cursor.fetchall()#获取所有结果
except:
print('报错')
#关闭连接
cursor.close()
connection.close()
data = pd.DataFrame(result)
网友评论