创建学生选课成绩视图score_view,显示选修3学分(含)学生学号(s_no)、姓名(s_name)、课程号(c_no)、课程名(c_name)、总成绩(total_score)。其中,总成绩按照——平时成绩*平时成绩比重+考试成绩*(1-平时成绩比重)公式计算。
时间: 2024-12-02 07:17:19 浏览: 17
创建名为`score_view`的视图,展示学生选择3学分及以上课程的成绩情况,包括学号(`s_no`)、姓名(`s_name`)、课程号(`c_no`)、课程名(`c_name`)和总成绩(`total_score`),可以这样定义:
```sql
CREATE VIEW score_view AS
SELECT s.no AS s_no, s.name AS s_name, c.cno AS c_no, c.cn AS c_name,
(c.p_score * p_weight + c.ex_score * (1 - p_weight)) AS total_score
FROM students s
JOIN courses c ON s.c_no = c.cno
JOIN course_scores cs ON s.s_no = cs.s_no AND c.cno = cs.cno
JOIN (SELECT cno, MAX(p_score) AS max_p_score FROM course_scores GROUP BY cno) AS max_p ON c.cno = max_p.cno
JOIN (
SELECT cno, AVG(p_score) AS avg_p_score FROM course_scores GROUP BY cno
) AS avg_p ON c.cno = avg_p.cno
WHERE c.credit_points >= 3
AND cs.p_score = max_p.max_p_score AND cs.ex_score = c.ex_score
AND cs.p_score = avg_p.avg_p_score * (p_weight * 100);
```
这里假设存在`students`表、`courses`表、`course_scores`表,分别记录学生信息、课程信息和成绩信息。`p_weight`表示平时成绩的比重,需要在实际应用中提供。
阅读全文