order by grade desc,sno asc;
④ 求选修课程C1成绩在80~90之间的学生学号和成绩,并将成绩乘以0.8输出 select sno,grade*0.85
from sc
where cno='1' and grade between 80 and 90;
⑤ 求数学或计算机系姓张的学生的信息
select * from student
where sdept in ('ma','is') and sname like '张%'
⑥ 求缺少了成绩的学生的学号和课程号
select sno,cno from sc
where grade is null;
2) 在图书借阅库中实现其查询操作。
① 将计算机类的书存入永久的计算机图书表
insert into yongjiu select * from tushu
where leibie='小说';
②将借阅日期在99年以前的借阅记录存入\\临时的超期借阅表
(2)连接查询实验
6
1) 在学生选课库中实现其数据连接查询操作。
① 查询每个学生的情况以及他(她)所选修的课程 select student.*,sc.cno
from student,sc
where student.sno=sc.sno;
② 求学生的学号、姓名、选修的课程及成绩 select student.sno,sname,cno,grade
from student,sc
where student.sno=sc.sno;
③ 求选修课程C1且成绩在90分以上的学生学号、姓名及成绩 select student.sno,sname,grade from student,sc
where student.sno=sc.sno and grade>90 and sc.cno='1'; ④ 查询每一门课的间接先行课(即先行课的先行课) select first.cno,second.cpno from course first,course second where first.cpno=second.cno;
2)在图书借阅库中实现其连接查询操作。
①查询借书者的编号、姓名、单位、所借书号、书名和借阅日期 select duzhe.bianhao,xingming,danwei,shuhao,riqi from duzhe,jieyue
where duzhe.bianhao=jieyue.bianhao 2.提高操作实验
7
l)建立职工部门库和职工、部门表,并向表中输入数据
职工表
职工号 1010 1011 1012 1014 姓名 李勇 刘晨 王敏 张立 性别 男 女 女 男 年龄 20 19 22 21 所在部门 11 14 12 13
create table 职工表 (
职工号 char(20) primary key, 姓名 char(20) unique, 性别 char(20), 年龄 smallint, 部门 char(20) );
部门表
部门号 11 12 13 14 部门名称 生产科 计划科 一车间 科研所 电话 566 578 467 create table 部门表 (
8
部门号 char(20) primary key, 部门名称 char(20) unique, 电话 char(20) );
2 )用T-SQL语句在职工部门库中实现其数据内连接和各种外查询操作。
② 内连接Select姓名,部门名称,电话 form 职工表,部门表
where职工表.所在部门=部门表.部门号
select 姓名,部门名称,电话 from 职工表,部门表
where 职工表.部门=部门表.部门号
③ 改为左外连接和右外连接
select 姓名,部门名称,电话 from 职工表left join 部门表on
(职工表.部门=部门表.部门号); select 姓名,部门名称,电话 from 职工表right join 部门表on (职工表.部门=部门表.部门号);
3.选择操作实验
(1) 设职工—社团库有三个基本 1)
建立职工.社团数据库和基本表,向库中输入一定的记录。
9
职工(职工号,姓名,负责人,活动地点) create table 职工 (
职工号 char(20) primary key, 姓名 char(20) unique, 负责人 char(20), 活动地点 char(20) );
社会团体(编号,名称,负责人,活动地点) create table 职工社团 (
编号 char(20) primary key, 名称 char(20) unique, 负责人 char(20), 活动地点 char(20) );
参加(职工号,编号,参加日期) create table 参加 (职工号 char(20), 编号 char (20), 活动地点 char(20),
primary key (职工号,编号),
foreign key (职工号) references 职工(职工号), foreign key (编号) references 社会团体(编号)
10