Teradata – Aggregate Functions

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.

EmployeeNoGrossDeductionNetPay
10140,0004,00036,000
10475,0005,00070,000
10280,0006,00074,000
10570,0004,00066,000
10390,0007,00083,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

This Post Has One Comment

  1. 후불출장

    Hey there! This post could not be written any better!
    Reading through this post reminds me of my good old room mate!
    He always kept chatting about this. I will forward this write-up to him.
    Fairly certain he will have a good read. Thanks for sharing!

Leave a Reply