mysql学习笔记(四)—— 1-10题练习讲解

1、 查询student表的所有数据。

select * from student;

查询student表的所有数据。

2、 查询student表中sname、ssex。

select sname,ssex from student;

查询表中sname与ssex字段。

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

select depart from teacher GROUP BY depart;

group by depart:根据 depart 分组 查询 depart

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

select * from score where score >= 60 and score <= 80;

where: 判断选择用

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

select * from score where score = 50 or score = 80 or score = 87;

6、查询student表中查学Java Web的或性别为“女"的同学记录。

select stu.sno,stu.sname,stu.sbirth,stu.ssex from student stu 
left join score sco on stu.sno=sco.sno
left join course cou on cou.cno=sco.cno
where cname = "Java Web" or ssex = "女";

left join:左连接,将两张表以主键字段拼接成一张表

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

select * from student order by sno desc;

order by:排序,默认为升序 desc 为降序

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

select * from score ORDER BY cno,score desc;

9、查询学Java Web的学生人数。

select count(stu.sno) from student stu
left join score sco on stu.sno=sco.sno
left join course cou on cou.cno=sco.cno
where cname = 'Java Web' ;

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

select sno,cno from score order by score desc limit 1;

limit 3: 取前三个

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值