当前位置:网站首页>Addition, deletion, modification and query of MySQL table (Advanced)
Addition, deletion, modification and query of MySQL table (Advanced)
2022-07-02 12:09:00 【The dishes are not right】
Catalog
🥬 newly added
insert into B select * from A;// take A The information of the table is added to B Go in the table
🥬 Aggregate query
count;// The total data returned to the query
sum;// The total data returned to the query ( Only meaningful for numbers )
Only meaningful for numbers
avg/max/min;// Return the average value of query data / Maximum / minimum value ( Only meaningful for numbers )
🥬 Group query
select * from Table name group by Grouping conditions ;
Here is to perform grouping first , Then execute the aggregation function of each group according to the Group .
🥬 Conditions of the query
having;
group by After the clauses are grouped , When the grouping results need to be conditionally filtered , You can use having.where Is performed before grouping , If you want to filter the results after grouping , You need to use having(having collocation group by Use ).
for example : Find the average salary for each role , Except Wu Jiu .( Here is the use of where, Specify conditions before grouping , First remove Wu Jiu , Find the average salary in groups .
Find the average salary for each role , Keep only the average salary 10000 Following , Here is to use having. You need to find out the average salary before you can filter .
🥬 The joint query
The first way to write it :select * from Table name 1, Table name 2;
The second way :select * from Table name 1 join Table name 2 on Conditions ;
The joint query ( More important ) It is a multi table query , The previous queries are all single table queries . Core operations in multi table query --- The cartesian product .
The operation of Cartesian product is to combine each record of two tables separately , Get a new set of records .
The above records are not all the results we want , We can get the results we want through screening .
that join on Followed by conditions and use where What's the difference with the conditions ?
from Multiple tables where It's called “ Internal connection ".
Use join on Writing , It can represent inner connection , It can also represent external connection .
select Name from surface 1 inner join surface 2 on Conditions ;inner join Said is " Internal connection " among inner It can be omitted .
select Name from surface 1 left join surface 2 on Conditions ; The left outer join .
select Column from surface 1 right join surface 2 on Conditions ; Right connection .
🥬 Self join
select s1.student_id,s1.score,s2.score from score as s1,score as s2 where s1.student_id=s2.student_id and s1.course_id=3 and s2.course_id=1 and s1.score>s2.score;
🥬 Merge query
union;// This can automatically remove the weight
union all;// This cannot be removed automatically
This operator is used to get the union of two result sets .
for example : Inquire about id Less than 3, Or the name is “ english ” Curriculum .
select * from course where id<3 union select * from course where name=' english ';
Or use or To achieve
select * from course where id<3 or name=' english ';
🥬 Summary
That's what we have today , If you have any questions, you can leave a message in the comment area
边栏推荐
- FastDateFormat为什么线程安全
- 输入一个三位的数字,输出它的个位数,十位数、百位数。
- 浅谈sklearn中的数据预处理
- Jenkins voucher management
- Data analysis - Matplotlib sample code
- (C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?
- 行業的分析
- Codeforces 771 div2 B (no one FST, refers to himself)
- [C language] Yang Hui triangle, customize the number of lines of the triangle
- SSH automatically disconnects (pretends to be dead) after a period of no operation
猜你喜欢
随机推荐
Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
Gaode map test case
GGPlot Examples Best Reference
Leetcode209 长度最小的子数组
还不会安装WSL 2?看这一篇文章就够了
求16以内正整数的阶乘,也就是n的阶层(0=<n<=16)。输入1111退出。
YYGH-BUG-04
Read the Flink source code and join Alibaba cloud Flink group..
ThreadLocal的简单理解
CDA数据分析——Excel数据处理的常见知识点归纳
YYGH-BUG-04
Mish-撼动深度学习ReLU激活函数的新继任者
How does Premiere (PR) import the preset mogrt template?
GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
Analyse de l'industrie
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
lombok常用注解
Deep understanding of P-R curve, ROC and AUC
PyTorch nn. Full analysis of RNN parameters