这一部分主要是视图相关的。
使用的还是刚才的那三张表。
1、为学生表创建一个视图V_XSQK,以显示学生的基本信息,如学号、姓名、性别和出生年月
CREATE VIEW V_VSQK AS SELECT sno,sname,ssex,sbirth FROM s
2、创建视图V_SC,要求显示学生的姓名、选修的课程名和成绩
CREATE VIEW v_sc AS SELECT s.sname,c.cname,sc.grade FROM s,c,sc WHERE s.sno = sc.sno AND c.cno = sc.cno
3、创建视图V_ST,显示在1981-1-1以后出生的学生信息,包括学号,姓名,性别和出生年月
CREATE VIEW v_st AS SELECT s.sno,s.sname,s.ssex,s.sbirth FROM s WHERE s.sbirth>1981-01-01
4、创建视图v_HG,显示成绩合格的学生信息,包括姓名、课程名和成绩
CREATE VIEW v_hg AS SELECT sname,cname,grade FROM s,sc,c WHERE s.sno = sc.sno AND c.cno = sc.cno AND grade>60
5、创建分组视图V_GP,要求查询每个学生的平均成绩,包括姓名,平均成绩
CREATE VIEW v_gp AS SELECT sname as 姓名, AVG(grade) AS 平均成绩 FROM s,sc WHERE s.sno = sc.sno GROUP BY sname
6、向视图V_XSQK中插入一条记录:‘2020206’,‘李红’,‘1983-12-3’
INSERT INTO v_vsqk VALUES ('2020206','李红','','1983-12-3')
7、修改视图V_XSQK,将李红同学是出生年月改为1982-12-3
UPDATE v_vsqk SET sbirth = '1982-12-3' WHERE sname = '李红'
8、删除视图V_XSQK中李红同学的信息
DELETE FROM v_vsqk WHERE sname = '李红'
9、删除视图V_XSQK
DROP VIEW v_vsqk
10、创建视图V_PJ,查询平均成绩在60分以上的学生信息,包括姓名和平均成绩
CREATE VIEW v_pj AS SELECT sname,AVG(grade) FROM s,sc WHERE s.sno = sc.sno GROUP BY sname HAVING AVG(grade)>60
um…这次的题目都有一些简单了。