数据库系统原理.docx
《数据库系统原理.docx》由会员分享,可在线阅读,更多相关《数据库系统原理.docx(9页珍藏版)》请在冰豆网上搜索。
数据库系统原理
《数据库系统原理》实验报告
姓名:
指导教师:
学号:
实验日期:
2016/6/7
一、实验目的
2、用SQL语句建立上述表,自定义主键和外键,对于student表建立约束条件:
ssex仅能取male或female;sage在18和22之间。
并完成下面的查询语句。
1、查询所有选修过“Bibliometrics”课的学生的姓名和成绩;
mysql>selects.sname,sc.gradefromstudentass,scwheres.snoin(selectsnofromscwheregrade>=60andcno='C05')and
sc.gradein(selectgradefromscwheregrade>=60andcno='C05');
2、查询考试成绩不及格的学生的个数;
mysql>selectcount(*)fromscwheregrade<60;
3、查询名字中至少含有一个“z”字符的学生的姓名、学号和性别;
mysql>selectsname,sno,ssexfromstudentwheresnamelike'%z%';
4、查询选修了“IntroductiontotheInternet”课程的学生的学号及其成绩,查询结果按分数的降序排列;
mysql>selectsno,gradefromscwherecnoin(selectcnofromcoursewherecnamelike"Introd%to%Inter%")orderbygradedesc;
5、查询“Zuoli”同学选修课程的总学时(time)数
mysql>selectsum(c.ctime)fromcoursecwherecnoin(selectcnofromscwheresnoin(selectsnofromstudentwheresname='Zuoli'));
6、查询年龄不大于20岁的学生的平均考试成绩;
mysql>selectavg(grade)fromscwheresnoin(selectsnofromstudentwheresage<=20);
7、查询“computerscience”专业学生选修“DatabaseSystem”的人数;
mysql>selectdistinctcount(sno)fromscwherecnoin(selectcnofromcoursewherecnamelike"D%Syst%")andsnoin(Selectsnofromstudentwheresdeptlike"compu%");
8、查询同时选修课程“DatabaseSystem”和“IntroductiontotheInternet”的学生姓名;
mysql>selectsnamefromstudentwheresnoin(selectsnofromscwherecnoin(selectcnofromcoursewherecnamelike"D%S%")union(selectcnofromcoursewherecnamelike'In%to%the%'));
9、查询选修的课程中含有“Wanggang”同学所有选修课程的学生姓名。
mysql>selectsnamefromstudentwheresnoin(selectsnofromscwherecnoin(selectcnofromscwheresnoin(selectsnofromstudentwheresname='Wanggang')));
10、查询“InformationTechnologyforInformationManagement”考试成绩为空的学生姓名及专业名称。
mysql>selectsname,sdeptfromstudentwheresnoin(selectsnofromscwheregradeisnull);
11、查询“computerscience”专业学生每个人的选修课总学分。
mysql>selectavg(grade)fromscwheresnoin(selectsnofromstudentwheresdeptlike'compu%');
12、查询个人考试平均成绩高于专业平均成绩的学生姓名
mysql>selectstu.snamefromstudentasstuwherestu.snoin(selectsnofromscwhere(selectavg(grade)fromscwheresno=stu.sno)>(selectavg(grade)fromsc));
13、查询个人考试平均成绩高于女生平均成绩的男生姓名
mysql>selectsnamefromstudentasstuwherestu.ssex='male'andstu.snoin(selectsnofromscwhere(selectavg(grade)fromscwheresno=stu.sno)>(selectavg(grade)fromscwheresnoin(selectsnofromstudentwheressex='female')));
14、查询比“computerscience”专业所有学生年龄都大的学生姓名。
mysql>select*fromstudentwheresdeptlike"com%"andsagein(selectmax(sage)fromstudentwheresdeptlike'com%');
15、查询考试成绩仅有一科不及格学生姓名
mysql>selectstu.snamefromstudentasstuwherestu.snoin(selectsnofromscwhere(selectcount(grade)fromscwhe
resno=stu.snoandgrade<60)=1);
THANKS!
!
!
致力为企业和个人提供合同协议,策划案计划书,学习课件等等
打造全网一站式需求
欢迎您的下载,资料仅供参考