查询练习
1.查询student表的所有记录。
select * from student;
2.查询student表中的所有sname、ssex和class列。
select sname,ssex,class from student;
3.查询教师所有的单位即不重复的depart列。
select distinct depart from teacher;
distinct排重
4.查询score表中成绩在60~80的所有记录(区间查询)。
select * from score where degree between 60 and 80;
between…and…区间
或者
select * from score where degree > 60 and degree < 80;
5.查询score表中成绩为78、88、89的记录(或关系查询)。
select * from score where degree in (78,88,89);
in在同一字段中的或查询
6.查询student表中“95001”班或女生的记录。
select * from student where class = '95001' or ssex = '女';
or不同字段的或查询
7.以class降序查询student表的所有记录。
升序(默认):asc;
降序:desc;
select * from student order by class desc;
8.以cno升序、degree降序查询score表的所有记录。
select * from score order by cno asc,degree desc;
先将cno升序排列,cno相同的以degree降序排列
9.查询“95002”班的学生人数。
select count(*) from student where class = "95002";
10.查询score表中的最高分的学生学号和课程号。(子查询或排序)
select sno,cno from score where degree = (select max(degree)from score);
实际步骤:
a.找到最高分select max(degree)from score;
b.找最高分的sno和cno。
11.查询每门课的平均成绩。