当前位置:网站首页>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
边栏推荐
- C#如何打印輸出原版數組
- Requests module (requests)
- 请求模块(requests)
- C语言课设学生考勤系统(大作业)
- 证券类开户有什么影响 开户安全吗
- Terminology description in the field of software engineering
- 问题解决:OfficeException: failed to start and connect(一)
- MySQL learning
- [ManageEngine Zhuohao] helps Huangshi Aikang hospital realize intelligent batch network equipment configuration management
- VS2019如何永久配置本地OpenCV4.5.5使用
猜你喜欢
JMM details
C language course set up property fee management system (big work)
How did ManageEngine Zhuohao achieve the goal of being selected into Gartner Magic Quadrant for four consecutive years?
Picture server project test
产品学习(三)——需求列表
lxml模块(数据提取)
Student attendance system for C language course (big homework)
Promise
C语言课设学生信息管理系统(大作业)
Mongodb: I. what is mongodb? Advantages and disadvantages of mongodb
随机推荐
JSON module
给逆序对数求原数组
@Transactional的传播属性REQUIRES_NEW深入理解
虚幻 简单的屏幕雨滴后处理效果
DML statement in SQL (data operation language)
Requests module (requests)
伪装请求头库: anti-useragent
PAT (Advanced Level) Practice 1057 Stack
脏读、幻读和不可重复读
C语言课设学生信息管理系统(大作业)
嵌入式系统
Promise
Rotate the animation component around the circle, take it and use it directly
Detailed steps for installing redis on Windows system
基金定投是高风险产品吗?
10 golang operator
[unity shader custom material panel part II]
To sort out the anomaly detection methods, just read this article!
2022 年江苏省职业院校技能大赛(中职) 网络搭建与应用赛项公开赛卷
[wechat applet] to solve button, input and image components