teradata supports common aggregate functions. they can be used with the select statement.
count − counts the rows
sum − sums up the values of the specified column(s)
max − returns the large value of the specified column
min − returns the minimum value of the specified column
avg − returns the average value of the specified column
example
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
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
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
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