软件测试-常见数据库笔试题

一、

1.新建表 test

id varchar2(20)
name varchar2(20)
addr varchar2(50)
score number

create table test
(id varchar2(20),
name varchar2(20),
addr varchar2(50),
score number
)

2.给id增加主键约束
alter table test add constraint pk_id primary key(id)
3.查询出分数大于60分的人员,并按分数降序进行排列

select * from test where score>60 order by score desc
4.新增数据 001 zhangsan shenzhen 80
insert into test(id,name,addr,score) values ('001','zhansgan','shenzhen','80')

  1. 将zhangsan的分数修改成60
    update test set score=60 where name='zhangsan'

7.删除zhangsan的信息

delete from test where name='zhangsan'

二、

Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表

问题:

1、查询平均成绩大于60分的同学的学号和平均成绩; avg

select s#,avg(score) from sc where (select avg(score) from sc)>60 group by s# ;

select s#,avg(score) from sc where group by s# having avg(score)>60;

2、查询所有同学的学号、姓名、选课数、总成绩;

select Student.s#,sname,count(C#),sum(score) from Student inner join sc on Student.s#=sc.s# group by Student.s#,sname

3、查询姓“李”的老师的个数;

select count(*) from teacher where tname like'李%'

4、查询没学过“叶平”老师课的同学的学号、姓名;

select S#,Sname from Student where s# in (select S# from sc where c# not in (select c# from Course where T#=(select T# from teacher where Tname='叶平' ))

5、查询所有课程成绩小于60分的同学的学号、姓名;

select S#,Sname from Student where s# not in (select S# from sc where score>60)

猜你喜欢

转载自blog.51cto.com/11170714/2174593