USE School GO Create Table Student( Sno char(12) Primary Key, Sname char(10) NOT NULL, Ssex char(2), Sbirthday date, Sdept char(2))
Create Table Course( Cno char(4) Primary Key, Cname char(20) NOT NULL, Cpno char(4) foreign key(Cpno) references Course(Cno), Ccredit int)
CREATE TABLE SC ( Sno CHAR(12), Cno CHAR(4), Score INT, PRIMARY KEY (Sno, Cno), FOREIGN KEY (Sno) REFERENCES Student(Sno), FOREIGN KEY (Cno) REFERENCES Course(Cno) );创建选修课程学分总数大于等于 10 学分的视图,包括学生学号、姓名、学分数。
To create a view that includes students who have a total credit score of 10 or more from their selected courses, including their student number, name, and total credit score, we can use the following SQL statement:
CREATE VIEW StudentCredits AS
SELECT
S.Sno,
S.Sname,
SUM(C.Ccredit) AS TotalCredits
FROM
Student S
JOIN SC ON S.Sno = SC.Sno
JOIN Course C ON SC.Cno = C.Cno
GROUP BY
S.Sno, S.Sname
HAVING
SUM(C.Ccredit) >= 10;
Let's break down this SQL statement:
StudentCredits
.In the SELECT clause:
Sno
) and name (Sname
) from the Student table.Ccredit
) from the Course table and alias it as TotalCredits
.In the FROM clause:
This view will show all students who have selected courses with a total credit score of 10 or more, along with their student number, name, and total credit score.