【SQL】4.test练习题及答案(1)

2017-06-05  本文已影响81人  一曈

1、 查询Student表中的所有记录的Sname、Ssex和Class列

select sname,ssex,class from student;
题目1

2、 查询教师所有的单位即不重复的Depart列

select distinct depart from teacher;
题目2

3、 查询Student表的所有记录

select * from student;
题目3

4、 查询Score表中成绩在60到80之间的所有记录

select * from score where degree between 60 and 80;
题目4

5、 查询Score表中成绩为85,86或88的记录

select * from score where degree in (85,86,88);
题目5

6、 查询Student表中“95031”班或性别为“女”的同学记录

select * from student where class='95031' or ssex='女';
题目6

7、 以Class降序查询Student表的所有记录。

select * from student order by class desc;
题目7

8、 以Cno升序、Degree降序查询Score表的所有记录。

select * from score order by cno,degree desc;
题目8

9、 查询“95031”班的学生人数。

select count(sname) from student where class='95031';
题目9

10、查询Score表中的最高分的学生学号和课程号。

select sno,cno from score where degree=(select max(degree) from score);
题目10

11、查询‘3-105’号课程的平均分。

select avg(degree) from score where cno='3-105';
题目11

12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。

 select avg(degree),cno from score
 where cno like '3%'
 group by cno
 having count(cno)>=5
题目12

13、查询最低分大于70,最高分小于90的Sno列。

select sno from score
group by sno
having max(degree)<90 and min(degree)>70;
题目13

14、查询所有学生的Sname、Cno和Degree列。

方法一
select s.sname,sc.cno,sc.degree from student s
join score sc on s.sno=sc.sno;
方法二
 select a.sname,b.cno,b.degree from student a,score b
 where a.sno=b.sno;
题目14

15、查询所有学生的Sno、Cname和Degree列。

方法一
select c.cname,sc.sno,sc.degree from course c
join score sc on c.cno=sc.cno;
方法二
select sc.sno,c.cname,sc.degree from score sc,course c
where sc.cno=c.cno;
题目15

16、查询所有学生的Sname、Cname和Degree列。

方法一
select s.sname,c.cname,sc.degree from student s
join (course c,score sc)
on s.sno=sc.sno and c.cno=sc.cno;
方法二
 select s.sname,c.cname,sc.degree from student s
 join score sc on sc.sno=s.sno
 join course c on c.cno=sc.cno;
题目16

17、查询“95033”班所选课程的平均分。

 select avg(degree) from score sc
 join student s
 on sc.sno = s.sno
 where s.class='95033';
题目17
上一篇 下一篇

猜你喜欢

热点阅读