Mysql练习#2-查询

Mysql练习#2-查询

查询练习

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表中成绩为85,86或88的记录

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

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

select * from student where class = '95013' or ssex = '女';

7、以class降序查询student表中的所有记录

select * from student order by class desc;

desc为降序,asc为升序(可以不写,默认为升序)

8、以cno升序、degree降序查询score表中的所有记录

select * from score order by cno asc,degree desc;

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

select count(*) from student where class = '95031';

10、查询score表中的最高分的学生学号和课程号(子查询或者排序)

子查询
select sno,cno from score where degree = (select max(degree) from score);

原文地址:https://www.cnblogs.com/DravenJH/p/14092305.html