sql聚合函数_SQL聚合函数

更新时间:2023-07-06 11:30:28 阅读: 评论:0

sql聚合函数_SQL聚合函数
sql聚合函数
Aggregate Functions basically operate on multiple columns to perform the operations and rve to reprent the output as
an entity reprenting the operation executed.
聚合函数基本上在多个列上进⾏操作以执⾏操作,并将输出表⽰为表⽰所执⾏操作的实体。
SQL Aggregate Functions SQL聚合函数
Syntax:
句法:
aggregate_function (DISTINCT | ALL expression)
DISTINCT enables the ur to lect distinct values from the if multiple attributes contain the same value, thenincubus
only single distinct value is considered for the calculations.
DISTINCT使⽤户可以从表中选择不同的值,即,如果多个属性包含相同的值,则仅考虑单个不同的值进⾏计算。
ALL makes sure that even the repeated values are considered for the calculations.
ALL确保即使重复值也被考虑⽤于计算。
SQL中的聚合函数: (Aggregate Functions in SQL:)
AVG()
AVG()
MIN()
lollipopMIN()
MAX()
MAX()
SUM()
和()
COUNT()
计数()
1. SQL AVG()函数 (1. SQL AVG() function)
SQL AVG() function returns the average of all the lected 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
表名称: 详细信息
ID Name Amount Age
1Safa500021
2Aman250023
3Rehaan2000025
4Seema1200025
ID名称量年龄
1个萨法500021
abandonment2阿曼250023
3瑞安2000025
4西玛1200025
Example:
例:
号码的英文
lect AVG(Amount) from Details;
Output:
输出:
9875
2. SQL MIN()函数 (2. SQL MIN() function)
SQL MIN() function returns the minimum value of all the lected values from the corresponding column of the table.
globecom
SQL MIN()函数从表的相应列返回所有选定值的最⼩值 。
Example:
例:
lect MIN(Amount) from Details;
charterOutput:
输出:
2500
3. SQL MAX()函数 (3. SQL MAX() function)
SQL MAX() function returns the maximum value of all the lected values from the corresponding column of the table.
SQL MAX()函数从表的相应列返回所有选定值的最⼤值 。
lect MAX(Amount) from Details;
Output:
输出:
20000
4. SQL SUM()函数 (4. SQL SUM() function)
abc字母歌
SQL SUM() function returns the summation of all the lected values from the corresponding column of the table.
SQL SUM()函数从表的相应列返回所有选定值的总和 。
vhf⽰例1: SUM()函数的基本理解 (Example 1: Basic Understanding of SUM() Function)
lect SUM(Amount) from Details;
Output:
输出:
39500
了不起的盖茨比原声
⽰例2:带有GROUP BY⼦句SQL SUM() (Example 2: SQL SUM() with GROUP BY Clau)
SQL SUM() can be framed together with SQL GROUP BY Clau to reprent 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 BY SUM()与GROUP BY
⽰例3:具有HAVING⼦句SQL SUM() (Example 3: SQL SUM() with HAVING Clau)
SQL SUM() function can be ud along with SQL HAVING Clau; HAVING Clau is basically ud to specify the condition
to be operated on the t of values in the table.
SQL SUM()函数可以与SQL HAVING⼦句⼀起使⽤。 HAVING⼦句基本上⽤于指定要对表中的⼀组值进⾏操作的条件。
SELECT SUM(Amount),Name
FROM Details
GROUP BY Name
HAVING SUM(Amount)>2500;
Output:
输出:
SUM() with HAVING Clau具有HAVING⼦句的SUM()
5. SQL COUNT()函数 (5. SQL COUNT() function)
⽰例 1: COUNT()函数返回表中特定列的计数 (Example 1: COUNT() function to return the count of
a particular column of a table)
lect COUNT(Amount) from Details;
Output:
输出:
4
blowaway⽰例2:COUNT(*)函数 (Example 2: COUNT(*) function) This function returns the count of all the values prent in the t of records of a table.
此函数返回表的记录集中存在的所有值的计数。
SELECT count(*) from Details;
Output:
输出:
4
⽰例3:带有WHERE⼦句的COUNT() (Example 3: COUNT() with WHERE Clau)
SELECT count(*) from Details
where Age<25;
‘Output:
输出:
2
⽰例4:COUNT()和GROUP BY⼦句 (Example 4: COUNT() with GROUP BY Clau)
SELECT count(Amount),Name from Details
where Age<25
Group by Name;
Output:
输出:
COUNT() with GROUP BY Clau COUNT()和GROUP BY⼦句
⽰例5:带有HAVING⼦句的COUNT() (Example 5: COUNT() with HAVING Clau)
SELECT count(Amount),Age, Name from Details
Group by Name
HAVING Age>=25;
Output:

本文发布于:2023-07-06 11:30:28,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/168831.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:函数   操作   返回   相应
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图