📜  avg mysql (1)

📅  最后修改于: 2023-12-03 14:39:24.539000             🧑  作者: Mango

Introduction to AVG in MySQL

In MySQL, the AVG function is used to calculate the average value of a specific column in a table.

Syntax

The syntax for using AVG in MySQL is as follows:

SELECT AVG(column_name) FROM table_name;
Example

Suppose we have a table named students, and we want to calculate the average age of all the students. We can use the AVG function as follows:

SELECT AVG(age) FROM students;

This will return a single value, which is the average age of all the students in the table.

NULL Values

It is important to note that the AVG function in MySQL ignores NULL values. If a column contains NULL values, those values will not be included in the calculation of the average.

Conclusion

The AVG function in MySQL is a powerful tool for calculating the average value of a specific column in a table. Whether you are working with large datasets or small ones, the AVG function can help you get the information you need quickly and efficiently.