数据库 实验四 select查询语句

实验四
一、实验目的
(1) 掌握SELECT语句在多表查询中的应用。
(2) 掌握多表连接的几种连接方式及应用。
二、实验要求
1、学生提前准备好实验报告,预习并熟悉实验步骤;
2、遵守实验室纪律,在规定的时间内完成要求的内容;
3、1~2人为1小组,实验过程中独立操作、相互学习。
三、实验内容及步骤
在Gradem数据库中完成下面查询:
(1)查询计算机工程系女学生的学生学号、姓名及考试成绩。
select a.sno,sname,degree
from student a,sc b
where a.sno=b.sno and sdept=‘计算机工程系’ and ssex=‘女’;

(2)查询“李勇”同学所选课程的成绩。
select cno,degree
from student a,sc b
where a.sno=b.sno and sname=‘李勇’;

(3)查询“李新”老师所授课程的课程名称。
select cname
from teacher a,teaching b,course c
where a.Tno=b.tno and b.cno=c.cno and Tname=‘李新’;

(4)查询女教师所授课程的课程号及课程名称。
select b.cno,cname
from teacher a,teaching b,course c
where a.Tno=b.tno and b.cno=c.cno and Tsex=‘女’;

(5)查询至少选修一门课程的女学生姓名。
select sname
from student a,sc b
where a.sno=b.sno and ssex=‘女’;

(6)查询姓“王”的学生所学的课程名称。
select cname
from student a,sc b,course c
where a.sno=b.sno and b.cno=c.cno and sname like ‘王%’;

(7)查询选修“数据库”课程且成绩在80~90分的学生学号及成绩。
select a.sno,degree
from sc a,course b
where a.cno=b.cno and cname=‘数据库原理及应用’ and degree between 80 and 90;

(8)查询课程成绩及格的男同学的学生信息及课程号与成绩。
select a.*,cno,degree
from student a,sc b
where a.sno=b.sno and degree>60 and ssex=‘男’;

(9)查询选修“C04”课程的学生的平均年龄。
select avg(year(curdate())-year(sbirthday))
from student a,sc b
where a.sno=b.sno and cno=‘c04’;

(10)查询选修课程名为“数学”的学生学号和姓名。
select a.sno,sname
from student a,sc b,course c
where a.sno=b.sno and b.cno=c.cno and cname=‘高等数学’;

(11)查询“钱军”教师任课的课程号,选修其课程的学生的学号和成绩。
select b.tno,sno,degree
from teacher a,teaching b,sc c
where a.Tno=b.tno and b.cno=c.cno and Tname=‘钱军’;

(12)查询在第3学期所开课程的课程名称及学生的成绩。
select cname,degree
from teaching a,course b,sc c
where a.cno=b.cno and b.cno=c.cno and cterm=3;

(13)查询“C02”课程不及格的学生信息。
select a.*
from student a,sc b
where a.sno=b.sno and cno=‘c02’ and degree<60;

(14)查询软件系成绩在90分以上的学生姓名、性别和课程名称。
select sname,ssex,cname
from student a,sc b,course c
where a.sno=b.sno and b.cno=c.cno and sdept=‘软件工程系’ and degree>90;

(15)查询同时选修了“C04”和“C02”课程的学生姓名和成绩。
select sname,b.degree,c.degree
from student a,sc b, sc c
where a.sno=b.sno and a.sno=c.sno and b.sno=c.sno and b.cno=‘c04’ and c.cno=‘c02’;

三、思考题
(1) 指定一个较短的别名有什么好处?
更加简洁易懂
(2)内连接与外连接有什么区别?
内连接查询操作列出与连接条件匹配的数据行;外连接,返回到查询结果集合中的不仅包含符合连接条件的行,而且还包括左表(左外连接)、右表(右外连接)或两个边接表(全外连接)中的所有数据行。
(3) “=”与IN在什么情况下作用相同?
in 里面的数据只有一个时,如 in(a) 与= a 一样的

  • 12
    点赞
  • 82
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值