Function : RANK with
Groupings
|
||||||||||||||||||||
Teradata Syntax:
We use the following Teradata syntax perform ranking with groups
Following
query gives employee with highest salary with department.
SELECT EMPLOYEEID,DEPARTMENTNO,SALARY,RANK(SALARY) AS RNK
FROM
EMPLOYEE
GROUP BY DEPARTMENTNO
QUALIFY
RNK = 1;
Thus
in Teradata Syntax:
|
||||||||||||||||||||
ANSI syntax:
We can get the same result by making use of ANSI syntax as follows: SELECT EMPLOYEEID,DEPARTMENTNO,SALARY,
RANK() OVER (PARTITION BY
DEPARTMENTNO ORDER BY SALARY DESC) AS RNK
FROM EMPLOYEE
QUALIFY
RNK = 1;
Thus
in ANSI syntax:
|
Blog Archive
-
►
2012
(22)
- ► January 2012 (21)
- ► February 2012 (1)
-
▼
2013
(119)
- ► February 2013 (2)
- ► March 2013 (28)
- ► April 2013 (48)
- ► September 2013 (16)
- ► October 2013 (3)
-
▼
November 2013
(13)
- 7.1 Teradata Parallel Transporter Export Operator ...
- 7.2 Teradata Parallel Transporter - Export Operato...
- 7.3 Teradata Parallel Transporter - Export Operato...
- 8.1 Teradata Parallel Transporter - SQL selector O...
- 8.2 Teradata Parallel Transporter - SQL selector -...
- 8.3 Teradata Parallel Transporter - SQL selector o...
- 9.1 Teradata Parallel Transporter - Load Operator ...
- 9.2 Teradata Parallel Transporter - Load Operator ...
- 9.3 Teradata Parallel Transporter - Load Operator ...
- 10.1 Teradata Parallel Transporter - SQL inserter ...
- 10.2 Teradata Parallel Transporter - SQL inserter ...
- 11.1 Teradata Parallel Transporter - Stream Operat...
- 11.2 Teradata Parallel Transporter - Stream Operat...
Showing posts with label ANSI AND teradata Equivalents. Show all posts
Showing posts with label ANSI AND teradata Equivalents. Show all posts
Sunday, 21 April 2013
ANSI and Teradata Function Equivalents - Part 2 - RANK with Grouping
ANSI and Teradata Function Equivalents - Part 1- RANK
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:
|
Subscribe to:
Posts (Atom)