200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > sql聚合函数_SQL聚合函数

sql聚合函数_SQL聚合函数

时间:2018-11-26 04:19:03

相关推荐

sql聚合函数_SQL聚合函数

sql聚合函数

SQL Aggregate Functions basically operate on multiple columns to perform the operations and serve to represent the output as an entity representing the operation executed.

SQL聚合函数基本上在多个列上进行操作以执行操作,并将输出表示为表示所执行操作的实体。

SQL Aggregate FunctionsSQL聚合函数

Syntax:

句法:

aggregate_function (DISTINCT | ALL expression)

DISTINCTenables the user to select distinct values from the table i.e. if multiple attributes contain the same value, then only single distinct value is considered for the calculations.DISTINCT使用户可以从表中选择不同的值,即,如果多个属性包含相同的值,则仅考虑单个不同的值进行计算。ALLmakes sure that even the repeated values are considered for the calculations.ALL确保即使重复值也被考虑用于计算。

SQL中的聚合函数:(Aggregate Functions in SQL:)

AVG()AVG()MIN()MIN()MAX()MAX()SUM()和()COUNT()计数()

1. SQL AVG()函数 (1. SQL AVG() function)

SQL AVG() function returns theaverageof all the selected values from the corresponding column of the table.

SQL AVG()函数从表的相应列返回所有选定值的平均值

Let’s us consider the following table to understand the Aggregate functions:

让我们考虑下表以了解Aggregate函数:

Table Name:Details

表名称:详细信息

Example:

例:

select AVG(Amount) from Details;

Output:

输出:

9875

2. SQL MIN()函数 (2. SQL MIN() function)

SQL MIN() function returns theminimum valueof all the selected values from the corresponding column of the table.

SQL MIN()函数从表的相应列返回所有选定值的最小值

Example:

例:

select MIN(Amount) from Details;

Output:

输出:

2500

3. SQL MAX()函数 (3. SQL MAX() function)

SQL MAX() function returns themaximum valueof all the selected values from the corresponding column of the table.

SQL MAX()函数从表的相应列返回所有选定值的最大值

select MAX(Amount) from Details;

Output:

输出:

20000

4. SQL SUM()函数 (4. SQL SUM() function)

SQL SUM() function returns thesummationof all the selected values from the corresponding column of the table.

SQL SUM()函数从表的相应列返回所有选定值的总和

示例1:SUM()函数的基本理解 (Example 1:Basic Understanding of SUM() Function)

select SUM(Amount) from Details;

Output:

输出:

39500

示例2:带有GROUP BY子句SQL SUM() (Example 2:SQL SUM() with GROUP BY Clause)

SQL SUM() can be framed together withSQL GROUP BY Clauseto represent the output results by a particular label/values.

SQL SUM()可以与SQL GROUP BY子句一起使用,以特定的标签/值表示输出结果。

SELECT SUM(Amount),Name FROM Details WHERE Age>21 GROUP BY Name;

Output:

输出:

SUM() with GROUP BYSUM()与GROUP BY

示例3:具有HAVING子句SQL SUM()(Example 3: SQL SUM() with HAVING Clause)

SQL SUM() function can be used along with SQL HAVING Clause; HAVING Clause is basically used to specify the condition to be operated on the set of values in the table.

SQL SUM()函数可以与SQL HAVING子句一起使用。 HAVING子句基本上用于指定要对表中的一组值进行操作的条件。

SELECT SUM(Amount),Name FROM Details GROUP BY NameHAVING SUM(Amount)>2500;

Output:

输出:

SUM() with HAVING Clause具有HAVING子句的SUM()

5. SQL COUNT()函数 (5. SQL COUNT() function)

示例1:COUNT()函数返回表中特定列的计数 (Example1:COUNT() function to return the count of a particular column of a table)

select COUNT(Amount) from Details;

Output:

输出:

4

示例2:COUNT(*)函数(Example 2: COUNT(*) function)

This function returns the count of all the values present in the set of records of a table.

此函数返回表的记录集中存在的所有值的计数。

SELECT count(*) from Details;

Output:

输出:

4

示例3:带有WHERE子句的COUNT()(Example 3: COUNT() with WHERE Clause)

SELECT count(*) from Detailswhere Age<25;

Output:

输出:

2

示例4:COUNT()和GROUP BY子句(Example 4: COUNT() with GROUP BY Clause)

SELECT count(Amount),Name from Detailswhere Age<25Group by Name;

Output:

输出:

COUNT() with GROUP BY ClauseCOUNT()和GROUP BY子句

示例5:带有HAVING子句的COUNT()(Example 5: COUNT() with HAVING Clause)

SELECT count(Amount),Age, Name from DetailsGroup by NameHAVING Age>=25;

Output:

输出:

COUNT() with HAVING ClauseCOUNT()和HAVING子句

结论 (Conclusion)

Thus, in this article, we have understood different SQL Aggregate Functions.

因此,在本文中,我们了解了不同SQL聚合函数。

参考 (Reference)

SQL DocumentationSQL文档

翻译自: /34288/sql-aggregate-functions

sql聚合函数

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。
相关阅读
SQL窗口函数-聚合窗口函数

SQL窗口函数-聚合窗口函数

2019-06-24

SQL聚合函数

SQL聚合函数

2022-01-17

【SQL】聚合函数

【SQL】聚合函数

2019-08-09

SQL 聚合函数

SQL 聚合函数

2022-05-17