• 请不要在回答技术问题时复制粘贴 AI 生成的内容
zxle
V2EX  ›  程序员

谁帮忙写三个sql语句

  •  
  •   zxle · Oct 17, 2011 · 4984 views
    This topic created in 5365 days ago, the information mentioned may be changed or developed.
    四个表:
    1学生表(学号 姓名 省份)
    2系表(系ID 系名 学号)
    3课程表(课程ID 名称 学生)
    4成绩表(学号 课程ID 成绩)

    要求写三个sql查询语句:
    1 列出选修课程最多学生
    2 列出选修“计算机原理”学生最少的系
    3 列出每个系成绩的及格率(系的学生所选课程及格数/总课程数)
    2 replies    2023-01-03 17:41:58 +08:00
    fmfsaisai
        1
    fmfsaisai  
       Oct 17, 2011
    我怎么感觉这个应该放在Bitcoin节点
    listenEcho
        2
    listenEcho  
       Jan 3, 2023
    1. To find the student who has taken the most courses:



    SELECT student, COUNT(*) as num_courses
    FROM courses
    GROUP BY student
    ORDER BY num_courses DESC
    LIMIT 1;


    2. To find the department with the least number of students taking the course "Computer Principles":

    SELECT department, COUNT(*) as num_students
    FROM students
    JOIN departments ON students.student_id = departments.student_id
    JOIN courses ON students.student_id = courses.student_id
    WHERE courses.name = 'Computer Principles'
    GROUP BY department
    ORDER BY num_students ASC
    LIMIT 1;


    3. To find the pass rate for each department (the percentage of courses passed by students in the department):

    SELECT department,
    SUM(CASE WHEN grades.grade >= 60 THEN 1 ELSE 0 END) / COUNT(*) AS pass_rate
    FROM students
    JOIN departments ON students.student_id = departments.student_id
    JOIN grades ON students.student_id = grades.student_id
    GROUP BY department;


    FROM ChatGPT
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1007 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 22:38 · PVG 06:38 · LAX 15:38 · JFK 18:38
    ♥ Do have faith in what you're doing.