Teradata 简明教程

Teradata - Aggregate Functions

Teradata 支持常见的聚合函数。它们可以与 SELECT 语句一起使用。

Teradata supports common aggregate functions. They can be used with the SELECT statement.

  1. COUNT − Counts the rows

  2. SUM − Sums up the values of the specified column(s)

  3. MAX − Returns the large value of the specified column

  4. MIN − Returns the minimum value of the specified column

  5. AVG − Returns the average value of the specified column

Example

请考虑以下 Salary 表。

Consider the following Salary Table.

EmployeeNo

Gross

Deduction

NetPay

101

40,000

4,000

36,000

104

75,000

5,000

70,000

102

80,000

6,000

74,000

105

70,000

4,000

66,000

103

90,000

7,000

83,000

COUNT

以下示例计算 Salary 表中的记录数。

The following example counts the number of records in the Salary table.

SELECT count(*) from Salary;

  Count(*)
-----------
    5

MAX

以下示例返回最大员工净薪水值。

The following example returns maximum employee net salary value.

SELECT max(NetPay) from Salary;
   Maximum(NetPay)
---------------------
       83000

MIN

以下示例从 Salary 表中返回最低员工净薪水值。

The following example returns minimum employee net salary value from the Salary table.

SELECT min(NetPay) from Salary;

   Minimum(NetPay)
---------------------
        36000

AVG

以下示例从表中返回员工净薪水值的平均值。

The following example returns the average of employees net salary value from the table.

SELECT avg(NetPay) from Salary;

   Average(NetPay)
---------------------
       65800

SUM

以下示例计算 Salary 表所有记录中员工净薪水总和。

The following example calculates the sum of employees net salary from all records of the Salary table.

SELECT sum(NetPay) from Salary;

   Sum(NetPay)
-----------------
     329000