← 返回题库
初级

查询已获证书的学员列表

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    instructors_csv = open_url("https://data.zuihe.com/dbd/education/state_D02/instructors.csv").read()
    courses_csv = open_url("https://data.zuihe.com/dbd/education/state_D02/courses.csv").read()
    students_csv = open_url("https://data.zuihe.com/dbd/education/state_D02/students.csv").read()
    enrollments_csv = open_url("https://data.zuihe.com/dbd/education/state_D02/enrollments.csv").read()
    assignments_csv = open_url("https://data.zuihe.com/dbd/education/state_D02/assignments.csv").read()
    submissions_csv = open_url("https://data.zuihe.com/dbd/education/state_D02/submissions.csv").read()
    certificates_csv = open_url("https://data.zuihe.com/dbd/education/state_D02/certificates.csv").read()
    import sqlite3
    import pandas as pd
    from io import StringIO

    conn = sqlite3.connect(':memory:')
    pd.read_csv(StringIO(certificates_csv)).to_sql('certificates', conn, index=False, if_exists='replace')
    pd.read_csv(StringIO(students_csv)).to_sql('students', conn, index=False, if_exists='replace')
    pd.read_csv(StringIO(courses_csv)).to_sql('courses', conn, index=False, if_exists='replace')

    result = pd.read_sql_query("""
        SELECT s.name AS student_name, c.title AS course_title,
               cert.cert_no, cert.issued_at
        FROM certificates cert
        JOIN students s ON cert.student_id = s.id
        JOIN courses c ON cert.course_id = c.id
        ORDER BY cert.issued_at
    """, conn)
    print(result.to_string(index=False))
    conn.close()

示例

输入
solve()
期望输出
student_name   course_title           cert_no           issued_at
          张伟    Python从零到精通 CERT-2025-001-001 2025-02-10 20:00:00
          李芳   Python数据分析实战 CERT-2025-002-002 2025-02-20 18:00:00
          王军     Python爬虫实战 CERT-2025-007-003 2025-03-01 19:00:00
          张伟       SQL数据库实战 CERT-2025-006-001 2025-03-05 20:00:00
          陈霞       SQL数据库实战 CERT-2025-006-004 2025-03-15 20:00:00
          刘洋   Python数据分析实战 CERT-2025-002-006 2025-04-01 20:00:00
          孙梅    Python自动化办公 CERT-2025-013-007 2025-04-05 21:00:00
          李芳 pandas数据清洗100题 CERT-2025-011-002 2025-04-10 19:00:00
          吴婷    Python从零到精通 CERT-2025-001-009 2025-04-20 19:00:00
          丁燕    Python从零到精通 CERT-2025-001-030 2025-04-28 18:00:00
          黄强       SQL数据库实战 CERT-2025-006-012 2025-04-28 20:00:00
          冯燕    Python自动化办公 CERT-2025-013-017 2025-04-30 20:00:00
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码