当前位置:网站首页>[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
边栏推荐
- Innovation training (VI) routing
- 信息学奥赛一本通 1212:LETTERS | OpenJudge 2.5 156:LETTERS
- MySQL -- execution process and principle of a statement
- KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
- No such file or directory problem while executing shell
- What is a data island? Why is there still a data island in 2022?
- 解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
- Opencv + clion face recognition + face model training
- Sword finger offer: the median in the data stream (priority queue large top heap small top heap leetcode 295)
- Recommended scheme for national production of electronic components for wireless charging
猜你喜欢
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
Field injection is not recommended using @ Autowired
Recommended scheme for national production of electronic components for wireless charging
AQS源码阅读
Detailed explanation of the differences between TCP and UDP
拼了!两所A级大学,六所B级大学,纷纷撤销软件工程硕士点!
Simply drag objects to the item bar
[WinUI3]编写一个仿Explorer文件管理器
[WinUI3]編寫一個仿Explorer文件管理器
随机推荐
JS generates a specified number of characters according to some words
Spark optimization
leetcode003--判断一个整数是否为回文数
Graduation project
Com alibaba. Common methods of fastjson
Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
COM in wine (2) -- basic code analysis
Innovation training (IX) integration
Spark FAQ sorting - must see before interview
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer
Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
信息学奥赛一本通 1212:LETTERS | OpenJudge 2.5 156:LETTERS
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
List< Map> Replication: light copy and deep copy
MySQL - data read / write separation, multi instance
New terminal play method: script guidance independent of technology stack
MySQL -- execution process and principle of a statement
What is a blocking queue? What is the implementation principle of blocking queue? How to use blocking queue to implement producer consumer model?
The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
Recommended scheme of national manufactured electronic components