1、 查询Student表中的所有记录的Sname、Ssex和Class列
select sname,ssex,class from student;
![](https://img.haomeiwen.com/i444773/a93e44728c6316d3.png)
2、 查询教师所有的单位即不重复的Depart列
select distinct depart from teacher;
![](https://img.haomeiwen.com/i444773/98b31e3d01ec410b.png)
3、 查询Student表的所有记录
select * from student;
![](https://img.haomeiwen.com/i444773/2b6fef60837b3d4a.png)
4、 查询Score表中成绩在60到80之间的所有记录
select * from score where degree between 60 and 80;
![](https://img.haomeiwen.com/i444773/bbc6cbdfdf3d0038.png)
5、 查询Score表中成绩为85,86或88的记录
select * from score where degree in (85,86,88);
![](https://img.haomeiwen.com/i444773/3f084a04e9250df8.png)
6、 查询Student表中“95031”班或性别为“女”的同学记录
select * from student where class='95031' or ssex='女';
![](https://img.haomeiwen.com/i444773/d7d997692ad578ec.png)
7、 以Class降序查询Student表的所有记录。
select * from student order by class desc;
![](https://img.haomeiwen.com/i444773/dd2064111894d4b9.png)
8、 以Cno升序、Degree降序查询Score表的所有记录。
select * from score order by cno,degree desc;
![](https://img.haomeiwen.com/i444773/8cd319469f1d6a9a.png)
9、 查询“95031”班的学生人数。
select count(sname) from student where class='95031';
![](https://img.haomeiwen.com/i444773/df96ff3d4a6e3e2b.png)
10、查询Score表中的最高分的学生学号和课程号。
select sno,cno from score where degree=(select max(degree) from score);
![](https://img.haomeiwen.com/i444773/3f1c63a34ea45a3f.png)
11、查询‘3-105’号课程的平均分。
select avg(degree) from score where cno='3-105';
![](https://img.haomeiwen.com/i444773/11172c9e71c2a10b.png)
12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
select avg(degree),cno from score
where cno like '3%'
group by cno
having count(cno)>=5
![](https://img.haomeiwen.com/i444773/33ac2fa26e860b8b.png)
13、查询最低分大于70,最高分小于90的Sno列。
select sno from score
group by sno
having max(degree)<90 and min(degree)>70;
![](https://img.haomeiwen.com/i444773/c16d9e7176cfd625.png)
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;
![](https://img.haomeiwen.com/i444773/ce455d648cb64e29.png)
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;
![](https://img.haomeiwen.com/i444773/c6b87836729a3fa4.png)
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;
![](https://img.haomeiwen.com/i444773/4880cf9196215a5d.png)
17、查询“95033”班所选课程的平均分。
select avg(degree) from score sc
join student s
on sc.sno = s.sno
where s.class='95033';
![](https://img.haomeiwen.com/i444773/1953ce1c94923afb.png)
网友评论