Mysql教程:(五)多表查询
多表查询
select name,student.class,student.number,maths,chinese,english from student,score where student.id=score.id;
1、题目练习
(1)显示总分大于200的学生信息:
select stu.name,sc.maths,sc.chinese,sc.english,sc.maths+sc.chinese+sc.english from student stu,score sc where stu.id=sc.id and sc.maths+sc.english+sc.chinese>200;
(2)显示班级总数大于等于20的班级:
select class,count(*) as total from student group by class having total>=20;
(3)显示人总数大于等于20的班级的成绩信息:
mysql> select sc.class,sc.number,sc.maths from score sc,(select class,count(*) as total from student group by class having total>=20) s where sc.class=s.class;
注释:
- commit:保存提交的意思,一般文件删除修改都要做保存;
- Rollback:撤回的意思,命令执行后;可以撤回为修改删除前的数据;
- truncate table score:永久删除的意思,尽量少用,删除则无记录找回;
- select now():查询现在的时间;
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
本文来自博客园,作者:hello_殷,转载请注明原文链接:https://www.cnblogs.com/yinzuopu/p/15516282.html
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。