四数据库写SQL题(3)

2019-03-15 17:27

5)将班编号以?02?开头的所有班级的辅导员修改为?李四? 答:1)create table students(s_id number(10) primary key, s_name varchar(30) not null, age number(3) not null, class varchar(20) not null, assistant varchar(30));

2)select s_id,s_name from students where age>20; 3)delete from students where class=?0201?; 4)select count(s_name) from students

where s_name like ?李%? and class='0302';

5)update students set assistant='李四' where class like '02%'; 21、表名:高考信息表 students_info 准考证号 科目 成绩 no subject score

2006001 语文 119 2006001 数学 108 2006002 物理 142 2006001 化学 136 2006001 物理 127 2006002 数学 149 2006002 英语 110 2006002 语文 105 2006001 英语 98 2006002 化学 129

写出高考总分在 600 以上的学生准考证号的 SQL 答: select no

from students_info group by no

having sum(score)>600;

22、有一个表 LEANR,表里有三个字段分别是学号(student_id), 课程(kc),成绩(grade) 。 1).查询每一门课程的前两名

2).查询以 Grade 降序排列的第 31 至 40 条记录(不需要区分课程)

3).查询表中存在课程重复 4 次以上的记录,显示课程和重复的次数,并且按照重复次数的降序排列 答:

1).select student_id,kc,grade

from (select student_id,kc,grade,

row_number() over(partition by kc order by grade desc)rn from LEANR) where rn<=2;

2)select student_id,grade from (

select lea.*,rownum rm

from ( select *

from LEANR

order by grade desc ) lea

where rownum < 41 )

where rm between 31 and 40; 3). select kc,count(kc) from LEANR group by kc

having count(kc)>=2 order by count(kc) desc; 23、a 部门表 b 员工表

a 表字段( id --部门编号 departmentName-部门名称 ) b 表字段( id--部门编号 employee- 员工名称 )

问题:如何一条 sql 语句查询出每个部门共有多少人 答:

建表语句: create table a(

id number primary key,

departmentName varchar(20) );

create table b( id number,

employee varchar(20) );

insert into a values(1,'部门 1'); insert into a values(2,'部门 2'); insert into a values(3,'部门 3'); insert into b values(1,'emp1'); insert into b values(1,'emp2'); insert into b values(1,'emp3'); insert into b values(2,'emp4'); insert into b values(2,'emp5'); insert into b values(3,'emp6');

select departmentName,count(employee) from a,b where a.id=b.id group by departmentName;

24、为管理岗位业务培训信息,建立 3 个表:

S (SID,SN,SD,SA) SID,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄

C (CID,CN ) CID,CN 分别代表课程编号、课程名称

SC ( SID,CID,G ) SID,CID,G 分别代表学号、所选修的课程编号、学习成绩

1. 使用标准 SQL 嵌套语句查询选修课程名称为?税收基础?的学员学号和姓名

2. 使用标准 SQL 嵌套语句查询选修课程编号为?02?的学员姓名和所属单位

3. 使用标准 SQL 嵌套语句查询不选修课程编号为?03?的学员姓名和所属单位

4. 使用标准 SQL 嵌套语句查询选修全部课程的学员姓名和所属单位

5. 查询选修课程超过 5 门的学员学号和所属单位 答:

建表 sql 语句: create table s( sid int(10) primary key, sn varchar(20) not null, sd varchar(20) not null, sa int(3) not null );

create table c( cid int(10) primary key, cn varchar(20) not null

);

create table sc(

sid int(10) references s(sid), cid int(10) references c(cid), g int(10),

primary key(sid,cid) );

insert into s values(1,\insert into s values(2,\

insert into s values(3,\insert into s values(4,\insert into c values(01,\税收基础\insert into c values(02,\insert into c values(03,\insert into sc values(1,01,70); insert into sc values(1,02,75); insert into sc values(1,03,80); insert into sc values(2,01,80); insert into sc values(2,03,69); insert into sc values(3,02,73); 1)

select s.sid,s.sn

from s,c,sc where s.sid=sc.sid and c.cid=sc.cid and c.name='税收基础'; 2) select a.sn,a.sd from s a, c b

where b.cid in(select c.cid from sc c where a.sid=c.sid and b.cid=c.cid) and b.cid=02; 3) select a.sn,a.sd from s a, c b

where b.cid not in(select c.cid from sc c where a.sid=c.sid and b.cid=c.cid) and b.cid=03; 4) select sn,sd from s where sid in

(select sid from sc group by sid having count(cid)=(select count(cid) from c));

5) select sn,sd from s

where sid in(select sid from sc group by sid having count(distinct cid)>5);

25、请根据以下要求来完成题目:

会议室预定模块:某公司有多个会议室,以房间号区分。如果某部门需要预定会议室,则会提交预定

请求(包含预定开始使用时间、预定结束使用,所预定会议室房间号) 。 设计一个表,保存会议室预定信息。


四数据库写SQL题(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:建筑业高级职称题库

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: