当前位置:网站首页>SQL learning notes 2
SQL learning notes 2
2022-07-01 06:35:00 【Small dollar】
Is a function that summarizes a set of data , The input is a set of data , The output is a single value , There are multiple arguments , There are multiple dependent variables
Common aggregate functions
sum()avg() Fields of type are not applicable to functions
max()min() Type applies to both string and time
count The number of statistics does not contain a null value
avg = sum / count
Aggregate function filtering null, If you query the average bonus rate of the company , use avg The function is wrong , Because the null value is not counted . Right should SELECT SUM(commission_pct) / COUNT(IFNULL(commission_pct,0)) FROM employees;
If you need to get accurate data in the table , those count More accurate ?
count(“*”),counut(1),count( Specific fields )
Different engines have different efficiency , however count(" *" )=count(1) This is the most efficient
group by Use
orderby Sort ,group by Grouping operation
A column to group , Group multiple columns
group by The statement in from Back
oderby front ,limit front
group by with rollup If it is to calculate the average salary of each department, add it to calculate the average salary of all the data at last
withrollup Unsuitable and orderby Sort , The results don't show , Because when sorting the Department salaries after grouping ,rollup Not at a level is not suitable for sorting
having Use
If an aggregate function is used in the filter condition , Then the condition must use having To replace where, Otherwise, the report will be wrong , If it does having Words ,having Request to put in group by Behind
Used in development having The premise is that group by
When there is an aggregate function in the filter condition, the filter condition must be declared in having in
If there is no aggregate function in the filter condition, the filter condition must be declared in where
where And having Comparison of
When querying multiple tables where More efficient
SQL The underlying query principle :
sql Statement execution :
First of all from 》 where》group by》having》select》distinct》orderby》limit
SQL The underlying principle of execution
Subquery :
Title : External query , Internal query , Main query ( External query ), Subquery ( Internal query )
Classification : Single line sub query , Multi line sub query
Whether the internal query is executed more than once : Correlation subquery , Uncorrelated subqueries
Symbols for multiline queries :
in Equal to any value in the list
any: Need to be used with single line , And any value
all: And all the values
some:any Another name for
边栏推荐
- Mysql 表分区创建方法
- webapck打包原理--启动过程分析
- 虚幻 简单的屏幕雨滴后处理效果
- 子类调用父类的同名方法和属性
- 阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]
- lxml模块(数据提取)
- 证券类开户有什么影响 开户安全吗
- What is a port scanning tool? What is the use of port scanning tools
- 10 golang operator
- Chapitre V gestion des entrées / sorties
猜你喜欢
随机推荐
SQL语句
问题解决:OfficeException: failed to start and connect(一)
Record MySQL troubleshooting caused by disk sector damage
C#如何打印输出原版数组
码力十足学量化|如何在财务报告寻找合适的财务公告
Rotate the animation component around the circle, take it and use it directly
On siem
Internet worm
B-tree series
webapck打包原理--启动过程分析
2022 Jiangsu Vocational College skills competition (secondary vocational school) network construction and application open competition volume
mysql学习
【微信小程序】一文解决button、input、image组件
PAT (Advanced Level) Practice 1057 Stack
给逆序对数求原数组
如果我在广州,到哪里开户比较好?究竟网上开户是否安全么?
[ITSM] what is ITSM and why does it department need ITSM
RestTemplate使用
【#Unity Shader#自定义材质面板_第二篇】
Teach you how to implement a deep learning framework








