Home > Database > Mysql Tutorial > body text

How to use aggregate functions in MySQL

WBOY
Release: 2023-06-02 15:34:06
forward
1544 people have browsed it

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)
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template