当前位置:网站首页>Data query of MySQL (aggregate function)
Data query of MySQL (aggregate function)
2022-07-26 12:18:00 【Yu'an.112】
SELECT The expression of clause can contain the so-called aggregate function (Aggregation Function). Aggregate functions are often used to calculate a set of values , And then return a single value . except COUNT() Out of function , Aggregate functions ignore null values . Aggregate functions are usually associated with GROUP BY Clauses are used together . if SELECT There is a GROUP BY Clause , Then the aggregate function works on all columns . If there is no , be SELECT Statement produces only one line as the result .
Common aggregate functions :
COUNT: Find the number of items in the group , return int Type integer
MAX: For maximum
MIN: For the minimum
SUM: Returns the sum of all values in an expression
AVG: Find the average of the group median
1、COUNT() function
The most commonly used in aggregate functions is COUNT() function , It is used to count the number of rows or total rows that meet the conditions in the table , return SELECT Statement retrieves rows that are not NULL The number of values , If no match is found , Then return to 0.
The grammar format is :COUNT( { [ALL | DISTINCT] expression } | *)
example : Ask the total number of members
SELECT COUNT(*)AS ' Number of members '
FROM Members;example : Count the number of closed orders
SELECT COUNT( Whether to settle )AS' Number of orders closed '
FROM Sell;2、MAX() Functions and MIN() function
MAX and MIN Functions are used to find the maximum and minimum values of all value items in the expression
Grammar format :MAX / MIN ([ALL | DISTINCT] expression )
example : Please order the book number IS-001 The maximum number of orders and the minimum number of orders
SELECT MAX( Number of copies ordered ),MIN( Number of copies ordered )
FROM Sell
WHERE Book number ='IS-001';3、SUM() Functions and AVG() function
SUM and AVG Respectively used to find the sum and average of all value items in the expression
Grammar format :SUM / AVG ( [ ALL | DISTINCT ] expression )
example : Please order the book number IS-01 The total number of books ordered
SELECT SUM( Number of copies ordered )AS' Total number of copies ordered '
FROM Sell
WHERE Book number ='IS-01';example : Please order books with the number IS-02 The average number of books ordered
SELECT AVG( Number of copies ordered )AS' The average number of copies per order '
FROM Sell
WHERE Book number ='IS-02';边栏推荐
- pytest接口自动化测试框架 | fixture调用fixture
- 一些常用的文章写作使用方法和技巧
- [map] universal map usage & two ways of fuzzy query
- 结合环境光、接近传感以及红外测距的光距感芯片4530A
- pytest接口自动化测试框架 | pytest的setup和teardown函数
- Network protocol: tcp/ip protocol
- Do you need to launch MES system? What are you struggling with?
- Who is responsible for the problems of virtual idol endorsement products? And listen to the lawyer's analysis
- 面试官:如何理解QPS,TPS,RT?
- QT入门引导 及其 案例讲解
猜你喜欢

二、容器_

基于STM32的SIM900A发送中文和英文短信

详解勒让德变换与共轭函数

字节流习题遇到的问题及解决方法

面试京东T5,被按在地上摩擦,鬼知道我经历了什么?

Introduction to FPGA (III) - 38 decoder

Introduction to FPGA (I) - the first FPGA project

On the construction and management of low code technology in logistics transportation platform

Flink's real-time data analysis practice in iFLYTEK AI marketing business

Here blog: running a large language model in a production environment - overview of the reasoning framework
随机推荐
Flink cdc 是不是只支持 sql-client的方式提交SQL脚本啊
Oracle AWR 报告脚本:SQL ordered by Elapsed Time
2、 Container_
pytest接口自动化测试框架 | 使用装饰器修饰需要运行的用例
Redis实现Single单点登入--系统框架搭建(一)
On the construction and management of low code technology in logistics transportation platform
Redis为什么这么快?Redis的线程模型与Redis多线程
el-form 每行显示两列,底部按钮居中
Pytorch深度学习快速入门教程 -- 土堆教程笔记(二)
Who is responsible for the problems of virtual idol endorsement products? And listen to the lawyer's analysis
【Mysql约束】
Overseas app push (Part 2): Channel Integration Guide for overseas manufacturers
DS-112时间继电器
flink 写redis 比较慢,大家有啥思路优化吗?
pytest接口自动化测试框架 | 使用多个fixture
STM32驱动HC05蓝牙串口通信模块
Question and answer No. 48: geek appointment - construction path of observable system
MySQL之数据查询(聚合函数)
Pytest interface automation test framework | pytest configuration file
Flutter's learning path