Home  >  Article  >  Database  >  How to use aggregate functions in MySQL

How to use aggregate functions in MySQL

WBOY
WBOYforward
2023-06-02 15:34:061453browse

Aggregation function

Commands: sum(), count(), avg(), max(), min()

Function: statistics, averaging Value, maximum, minimum value

Application scenarios: This type of function is very common and is mainly used for data statistics. It is also applicable in SQL optimization.

Example:

mysql> select max(id) from t_base_user;
+---------+
| max(id) |
+---------+
| 2 |
+---------+
1 row in set (0.00 sec)

Here is a little trick. If the primary key is increasing in order, when you need how many users there are, you can use max(id) instead of the count(*) function.

The above is the detailed content of How to use aggregate functions in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete