当前位置:网站首页>Advanced SQL query
Advanced SQL query
2022-06-09 07:46:00 【GUTSZ】
senior SQL Inquire about
1. Aggregate query
1. Common aggregate functions are :
1.1count function
count Used to query the number of entries .
1.count usage 1:
2.count usage 2:
You can query all the data (null+ Not null), Compatibility is not very good ,mysql have access to , Other databases may not work .
3.count usage 3:
4. summary :
In different count Statistical scenario , Use a different count Inquire about
(1) To query the quantity of all data (null+ Not null) Just use ->count(*)
(2) If you want to query all non Null You can use count( Field name ), It is not recommended to use , For the statistics of special scenarios, consider usingcount(*)+where Conditions of the query
1.2sum Sum Statistics

And statistics , If there is null, Or statistics of non integer values , The result is that only valid integer values are counted .
1.3avg Calculate average

avg When calculating the average , If there are data that do not conform to the specifications ( Such as NULL) This row of data will be discarded directly , Do not participate in the operation .
1.4max Maximum

1.5min minimum value


1.6iffull function
1. Judge whether it is null Function of , You can take two parameters , If the first parameter is not null, Then return the first parameter , Otherwise, the second parameter is returned .
2. grammar :
IFNULL(expression_1,expression_2);
If expression_1 Not for NULL, be IFNULL The function returns expression_1, Otherwise return to expression_2 Result .
Example :
SELECT IFNULL(1,0); -- returns 1
3. The total score is Null The problem of :
Use ifnull Function to solve the above problem :

2. Group query group by
1. grammar :
group by Is in where After the query , And its execution sequence is also in where after .
select column1, sum(column2), .. from table group by column1,column3;
2. Example :
Query the maximum salary for each role 、 Minimum and average wages .
2.1 Grouping query criteria having
1.group by⼦ Sentence into ⾏ After grouping , You need to re group the results ⾏ Conditional filtering , Can't make ⽤ where sentence ,⽽ Need to use having.having Query for filtering group by Data in .
2.having Is in group by Then the conditions , Its execution sequence is also in group by after .
3. Example :
It shows that the average wage is lower than 1500 And its average salary :
边栏推荐
- Apache configuration and application (building web host, log segmentation and awstats analysis system)
- Interpretation of the functions of the navigation system in the government hall
- Understand the whole test process with one diagram
- 通达信股票开户怎么样?开户安全吗?
- Some pitfalls encountered in using Renren open source project
- How about opening an account for shares of tongdaxin? Is it safe to open an account?
- Pycharm and MySQL as a student information management system
- 谈谈实施数据治理时常犯的十大错误
- Installing MySQL using docker
- ftp服务
猜你喜欢

PostgreSQL database replication - background first-class citizen process walreceiver extracts information

Boot Black apple with OpenCORE

Oracle: Foundation

PostgreSQL数据库信号量机制— PGSemaphore底层原理

Use of thread pool

Use of Shopify port in EDI system of bridge of knowledge and Practice

Apache 网页与安全优化
![[guide to stepping on the big pit] CSharp_ Process_ Prompt after running: no such file or pyinstaller prompt badzip, etc](/img/4a/e99262d7730b023d2b5cfc7291884b.png)
[guide to stepping on the big pit] CSharp_ Process_ Prompt after running: no such file or pyinstaller prompt badzip, etc

Related methods of thread class

MySQL: single table query
随机推荐
【学校实验+蓝桥杯题目】接水问题:学校里有一个水房,水房里一共装有m个龙头可供同学们打开水,每个龙头每秒钟的供水量相等,均为1。现在有n名同学准备接水,他们的初始接水顺序已经确定......
To your own ups and downs -- for you who just entered the testing industry
TCP transmission control protocol
Specific steps for yolov5 to add attention mechanism
[learning records of the first week in June] UU computer vision (1):3d Reconstruction & camera calibration
Robot_ Framework: common built-in keywords
Push related summary
Interpretation of the functions of the navigation system in the government hall
ftp服务
Phaser setting image resource size
CV学习笔记-CNN-VGG
Producer consumer issues
UML summary
PostgreSQL数据库复制——后台一等公民进程WalReceiver 提取信息
redis核心知識點總結(超詳細)
MySQL: grouping query
An integrated framework for caching, loading, refreshing and mapping data dictionaries
How about opening an account for shares of tongdaxin? Is it safe to open an account?
Use of qflags flag class
通达信股票开户怎么样?开户安全吗?