1、查询 student表中的所有行
select *from student;
2、查询student 表中的name、class字段的所有行
select name,class from student;
3、查询teacher表中不重复的department 列;
select distinct department 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 表中成绩为85,86或者88的行
这里用到in这个字符,in:查询多个数据
select *from score where degree in(85,86,88);
6、查询student 表中’95031‘班中或者性别为’女’的所有行
or表示或者的关系
select *from student where class ='90531' or sex='女';
7、以class降序查询student表中所有的记录
desc 降序 从高到底,asc :升序,从低到高
select *from student order by class desc;
select *from student order by class asc;
8、以 c_no 升序、degree 降序查询 score 表的所有行
select *from score order by c_no asc,degree desc;
9、.查询’95031’班的学生人数
count:统计
select count(*) from student where class=’95031';
10、查询 score 表中的最高分的学生学号和课程编号(子查询或排序查询)。
子查询算出最高分
select max(degree) from score;
select s_no,c_no from score where degree=(select max(degree) from score);
排序查询
select s_no,c_no,degree from score order by degree desc limit 0,1;
limit 0,1 中0表示从第1个开始记录,1表示记录个数为1个;
2146

被折叠的 条评论
为什么被折叠?



