import mysql.connector
# 连接数据库
db = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="yourdatabase"
)
# 创建游标对象
cursor = db.cursor()
# 执行SQL查询
query = "SELECT student_id, paper_count FROM student_paper_count ORDER BY paper_count DESC"
cursor.execute(query)
# 获取结果
results = cursor.fetchall()
# 输出结果
for (student_id, paper_count) in results:
print(f"Student ID: {student_id}, Paper Count: {paper_count}")
]]>