Mysql教程:(五)多表查詢
阿新 • • 發佈:2021-11-06
多表查詢
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
本文版權歸作者和部落格園共有,歡迎轉載,但必須給出原文連結,並保留此段宣告,否則保留追究法律責任的權利。