mysql查询练习

学生表

Student

学号

姓名

性别

出生年月日

所在班级

 

课程表

Course

课程号

课程名称

教师编号

成绩表

Score

学号

课程号

成绩

教师表

Teacher

教师编号

教师名字

教师性别

出生年月日

职称

所在部门

 

-----往数据表中添加数据

#添加学生信息

#添加教师表

#添加课程表

#添加成绩表

查询练习:

1 查询student表中的所有记录

select * from student;

2 查询student表中的所有记录的 sname,ssex,和class列

select sname, ssex, class from student

3 查询教师所有的单位即不重复的depart 列

distinct  排重

select  distinct depart from student;

4 查询score 表中成绩在60-80之间的所有记录

---查询区间  between ...and ...

select  * from score where degree  between 60 and 80
 
select * from score where degree > 60 and degree < 80

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

表示或者关系的查询 in


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

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

--- or  表示或者

select * from student from class = "95031" or ssex = "女"

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

  升序,降序如何表达  asc 升序  desc 降序

select * from student  order by class desc

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

   

select * from student 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 )

 11.

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值