【MySQL】Aggregate Functions|MAX() MIN() SUM() AVG() COUNT()

本記事にはプロモーションが含まれています。

Aggregate functions are indispensable when analyzing data in MySQL. These functions perform specific calculations on a dataset, providing valuable information. In this section, we will explain the types of aggregate functions commonly used and how to use them.

▼For information on the tables used in this article, please refer to this link.

▼youtube

youtube
【知識0からMySQL】データの検索①データベース作成

youtube
【MySQL】データの検索|WHERE句 LIKE 集計関数 AS GROUP BY ORDER BY LIMIT サブクエリ

Using the MAX Function

The MAX function returns the highest value in a specified column. For example, to find the highest score in the entry_exam column of the students table, you would use the following query:

Using the MIN Function

The MIN function returns the smallest value in a column. To find the lowest score in the students table, you would use this query:

Calculating Total Value with the SUM Function

The SUM function calculates the total of all values in a column. To find the total of scores in the entry_exam column, you would use:

Calculating Average Value with the AVG Function

The AVG function returns the average value of a column. To find the average score in the entry_exam column of the students table, you can use this query:

Counting Data with the COUNT Function

The COUNT function counts the number of data entries in a column. For example, to find the number of records that have data in the entry_exam column, you would use:

Summary

Aggregate functions are a powerful tool in data analysis. By mastering these functions, you can gain valuable insights from the information within your database. However, when using aggregate functions, it’s important to understand the nature of your data and the purpose of your analysis.

タイトルとURLをコピーしました