用SQL语句查询计算机科学系中选修课程门数大于刘德华同学(也是计算机科学系)所选课程门数的所有的学生姓名的选课门数及加权平均成绩,要求选课门数和加权平均成绩都按降序输出。【注:加权平均成绩等于所有课程的学分与成绩之和除以所有课程学分之和】
时间: 2024-05-28 07:14:57 浏览: 92
这是一个技术问题,我可以回答。以下是SQL语句:
SELECT student.name, COUNT(selected_course.course_id) as num_course, SUM(selected_course.credit*selected_course.score)/SUM(selected_course.credit) as avg_score
FROM student
LEFT JOIN selected_course ON student.student_id = selected_course.student_id AND selected_course.course_type = "elective"
WHERE student.department_name = "计算机科学系"
GROUP BY student.student_id
HAVING num_course > (
SELECT COUNT(course_id)
FROM selected_course
WHERE student_id = (
SELECT student_id
FROM student
WHERE name = "刘德华"
)
AND course_type = "elective"
)
ORDER BY num_course DESC, avg_score DESC;
阅读全文