当前位置:网站首页>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
边栏推荐
猜你喜欢
![[ManageEngine] how to realize network automatic operation and maintenance](/img/8a/75332d3180f92c6a6482d881032bbf.png)
[ManageEngine] how to realize network automatic operation and maintenance

产品学习(二)——竞品分析

【微信小程序低代码开发】二,在实操中化解小程序的代码组成

【#Unity Shader#自定义材质面板_第二篇】

Embedded system

C language course set up library information management system (big homework)

SQL statement

脏读、幻读和不可重复读

Promise

On whether variables are thread safe
随机推荐
@Propagation property of transactional requires_ New in-depth understanding
问题:OfficeException: failed to start and connect(二)
Is the account opening of Huafu securities safe and reliable? How to open Huafu securities account
三分钟带你快速了解网站开发的整个流程
[wechat applet] how to build a building block development?
DML statement in SQL (data operation language)
给逆序对数求原数组
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform
mysql学习
C语言课设学生选修课程系统(大作业)
NOC 设计的一些坑
C语言课设学生信息管理系统(大作业)
Several ways of gson's @jsonadapter annotation
【Unity Shader 消融效果_案例分享】
C language course design student information management system (big homework)
Mysql 表分区创建方法
存储过程学习笔记
RestTemplate使用
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
Chapter V input / output (i/o) management