Each
Teradata OLAP function that we have seen have ANSI equivalents.
ANSI
equivalents are sometimes tedious to write.
Following
Table shows the Teradata OLAP functions and its ANSI equivalent.
Function: RANK
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Teradata
Syntax:
Following
is how we write the Teradata RANK function:
SELECT EMPLOYEEID,SALARY, RANK (SALARY) FROM
EMPLOYEE;
The
Column name in the brackets indicate the column to be used for ranking and ordering data.
In
this syntax the highest value gets rank 1 by default.
Thus
in Teradata Syntax:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ANIS Syntax:
Following is how we write the RANK function in ANSI: SELECT EMPLOYEEID,SALARY,RANK() OVER (ORDER BY SALARY DESC) FROM EMPLOYEE;
The column specified by ORDER BY indicates the column to be used for ranking. Note the word DESC. DESC indicates that ordering is Descending .ie highest value gets 1st rank. Note that this is by default in Teradata syntax, but not in ANSI syntax. So we need to add DESC in the syntax. if we don't add DESC, then default in ANSI syntax is ASC, which means the lowest value gets rank 1 and highest value gets highest rank.
Ex:
SELECT EMPLOYEEID,SALARY,RANK() OVER (ORDER BY SALARY/*BY DEFAULT ORDERING IS ASC*/) FROM EMPLOYEE;
Thus
in ANSI syntax:
|
No comments:
Post a Comment