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():查询现在的时间;

posted on 2021-11-06 11:37  hello_殷  阅读(114)  评论(0编辑  收藏  举报

导航

作者:hello.殷
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。