当前位置:网站首页>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

边栏推荐
- 【C语言】杨辉三角,自定义三角的行数
- BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
- 基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)
- 机械臂速成小指南(七):机械臂位姿的描述方法
- Applet link generation
- Dynamic debugging of multi file program x32dbg
- Test shift left and right
- Pytorch builds LSTM to realize clothing classification (fashionmnist)
- [C language] convert decimal numbers to binary numbers
- PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing
猜你喜欢

Jenkins voucher management

YYGH-BUG-05

自然语言处理系列(三)——LSTM

HR wonderful dividing line

堆(优先级队列)

(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?

Deep understanding of NN in pytorch Embedding

Experiment of connecting mobile phone hotspot based on Arduino and esp8266 (successful)

机械臂速成小指南(七):机械臂位姿的描述方法

还不会安装WSL 2?看这一篇文章就够了
随机推荐
基于Arduino和ESP8266的连接手机热点实验(成功)
自然语言处理系列(三)——LSTM
Gaode map test case
小程序链接生成
Map和Set
Depth filter of SvO2 series
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
字符串回文hash 模板题 O(1)判字符串是否回文
史上最易懂的f-string教程,收藏这一篇就够了
FastDateFormat为什么线程安全
to_ Bytes and from_ Bytes simple example
drools决策表的简单使用
Maximum profit of jz63 shares
【2022 ACTF-wp】
堆(优先级队列)
mysql表的增删改查(进阶)
CONDA common command summary
Seriation in R: How to Optimally Order Objects in a Data Matrice
【C语言】十进制数转换成二进制数
post请求体内容无法重复获取
