[MySQL光速入门]009 SQL强化练习答案

1. 查询 Student 表中的所有记录的 Sname、Ssex 和 Class 列。

select sname,ssex,class from Student;
复制代码

2. 查询教师所有的单位即不重复的 Depart 列。

select distinct depart from teacher;
复制代码

3. 查询 Student 表的所有记录。

select * from student;
复制代码

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

select * from score where Degree between 60 and 80;
复制代码

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

select * from score where Degree in (85,86,88);
复制代码

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

select * from Student WHERE class="95031" or ssex = "女";
复制代码

7. 以 Class 降序查询 Student 表的所有记录。

select * from student order by class desc;
复制代码

8. 以 Cno 升序、Degree 降序查询 Score 表的所有记录。

select * from score order by cno asc,degree desc;
复制代码

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

select count(*) as 学生人数 from Student where class="95031"
复制代码

10. 查询 Score 表中的最高分的学生学号和课程号。

select cno,sno from Score order by degree desc limit 1;
复制代码

11. 查询每门课的平均成绩。

select cno,avg(degree) from Score GROUP BY cno;
复制代码

12. 查询分数大于 70,小于 90 的 Sno 列。

select sno,degree from score where degree > 70 and degree < 90;
复制代码

13. 查询所有学生的 Sname、Cno 和 Degree 列。

SELECT
	sname,
	cno,
	degree 
FROM
	student
	INNER JOIN score ON score.sno = Student.sno;
复制代码

14. 查询所有学生的 Sno、Cname 和 Degree 列。

SELECT
	sno,
	cname,
	degree 
FROM
	course
	INNER JOIN score ON score.cno = course.cno;
复制代码

15. 查询所有学生的 Sname、Cname 和 Degree 列。

SELECT
	sname,
	cname,
	degree 
FROM
	Student,
	course,
	Score 
WHERE
	Student.sno = score.sno 
	AND course.cno = score.cno;
	
	
SELECT
	sname,
	cname,
	degree 
FROM
	course
	INNER JOIN score ON score.cno = course.cno
	INNER JOIN student ON score.sno = Student.sno;
复制代码

16. 查询 95033 班和 95031 班全体学生的记录。

SELECT
	* 
FROM
	course
	INNER JOIN score ON score.cno = course.cno
	INNER JOIN student ON score.sno = Student.sno 
WHERE
	class = "95031" 
	OR class = "95033";
复制代码

17. 查询存在有 85 分以上成绩的课程 Cno。

select cno from score WHERE degree > 85;
复制代码

18. 查询 Student 表中不姓“王”的同学记录。

select * from student WHERE sname not like "王%";
复制代码

19. 以班号和年龄从大到小的顺序查询 Student 表中的全部记录。

select * from student order by class desc,sbirthday asc;
复制代码

快速跳转

转载于:https://juejin.im/post/5c9b30bb6fb9a0710c704815

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值