当前位置:网站首页>[database] MySQL multi table query (I)
[database] MySQL multi table query (I)
2022-04-23 04:52:00 【Minglu peanut milk】
Exercise four ( One ) Multi-table query
One 、 Link query
- Check the student number and total score of female students
Let's take a look first jxgl Tables in the database :

Check the student number and total score of female students , We found that sc There is no gender column in the table ,student There is a gender in the table , however student There are no grades in the table .
Therefore, through this step, we will introduce the main content of this chapter ----> Multi-table query ;
Convenient observation , I'll stick it here first sc Table and student surface


The operation is as follows :
![]()
There is the following situation , Why? ?
MySQL Of sql_mode yes only_full_group_by When , Without using group by also select If the aggregation function appears later , So by all select All should use aggregate functions ( For example, in this case sum function ). Otherwise, such errors will be reported ;
Tips: stay select The specified field must either be included in group by After statement , As a basis for grouping ; Or it's included in the aggregate function

2. Query the course number and grade selected by Li Yong
The course number and grade are in sc table , But the student's name is in student table , Therefore, it is multi table query
So it's straightforward to operate :

Maybe I think it's not bad , But take a closer look , In fact, there are problems :select What's the matter sc The whole of the watch !
There is a problem !!!!!!!!!!!!!


Then let's take a look at the previous choice :
3. Query the course name of the course taught by Mr. Li Xin
First of all, the course name is course table :

Then the teacher's name is in teacher table :

But when we look at these two tables, we can easily find , There are no fields on these two tables that can be matched , So an exception is needed teaching surface :

Do something :

4. Check the course number and course name of the course given by the female teacher

5. Check the last name “ king ” The name of the course the students learned
Wildcards are needed here % 了

6. Check options “ database ” Course and grade in 80 To 90 Student number and grades between

7. Check options “C03” The average age of the students in the course

But if Party A is tricky , Just two decimal places , Need cast Functions like this :

But Party A thinks the name of this field is too long , Change to average age

8. The query learning course is named “ database ” Student ID and name of

9. Inquire about ” Li Xin ” The course number of the teacher , The student number and grades of the students taking their courses

10. The query is on page 3 The course name of the course offered in the semester , Student number and grades of students taking their courses

版权声明
本文为[Minglu peanut milk]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230446089113.html
边栏推荐
- JS generates a specified number of characters according to some words
- MySQL -- execution process and principle of a statement
- Raspberry pie + opencv + opencv -- face detection ------- environment construction
- Sword finger offer: the path with a certain value in the binary tree (backtracking)
- Innovative practice of short video content understanding and generation technology in meituan
- Progress of innovation training (IV)
- Record the blind injection script
- Code007 -- determine whether the string in parentheses matches
- Unity rawimage background seamlessly connected mobile
- Wechat payment function
猜你喜欢

【数据库】MySQL单表查询

Record the ThreadPoolExecutor main thread waiting for sub threads

What is a data island? Why is there still a data island in 2022?

Flink's important basics

Wine (COM) - basic concept

Recommended scheme of national manufactured electronic components
![[winui3] Écrivez une copie du gestionnaire de fichiers Explorer](/img/3e/62794f1939da7f36f7a4e9dbf0aa7a.png)
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer

拼了!两所A级大学,六所B级大学,纷纷撤销软件工程硕士点!

Spark small case - RDD, spark SQL

Perfect test of coil in wireless charging system with LCR meter
随机推荐
leetcode003--判断一个整数是否为回文数
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
DIY 一个 Excel 版的子网计算器
Pixel mobile phone brick rescue tutorial
独立站运营 | FaceBook营销神器——聊天机器人ManyChat
Jetpack -- lifecycle usage and source code analysis
Arduino UNO r3+LCD1602+DHT11
PHP+MySQL 制作留言板
Innovation training (II) task division
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
IEEE Transactions on industrial information (TII)
Innovative practice of short video content understanding and generation technology in meituan
leetcode002--将有符号整数的数字部分反转
【数据库】MySQL单表查询
Leetcode004 -- Roman numeral to integer
Innovation training (VII) FBV view & CBV view
PIP3 installation requests Library - the most complete pit sorting
[WinUI3]編寫一個仿Explorer文件管理器