Blog Archive

Sunday, 28 April 2013

Teradata MAX window Function



Maximum Window Function:
 
Just as minimum window function we also have maximum window function.

Maximum window function is used to get maximum value for the defined group.

 
SELECT        EMPLOYEEID,DEPARTMENTNO,SALARY,

MAX(SALARY) OVER (
ORDER        BY DEPARTMENTNO)
FROM        EMPLOYEE2;


Employeeid
DepartmentNo
Salary
Group Max(Salary)
9
100
9000
12345.11
5
100
5000
12345.11
1
100
1000
12345.11
124
200
12345.11
12345.11
10
200
10000
12345.11
6
200
6000
12345.11
2
200
2000
12345.11
11
300
11000
12345.11
3
300
3000
12345.11
7
300
7000
12345.11
12
400
12000
12345.11
4
400
4000
12345.11
8
400
8000
12345.11
144
400
12345.11
12345.11

Using PARTITION BY clause we can find maximum per group.

 
SELECT        EMPLOYEEID,DEPARTMENTNO,SALARY,
MAX(SALARY) OVER ( PARTITION BY DEPARTMENTNO

ORDER        BY DEPARTMENTNO ROWS BETWEEN UNBOUNDED PRECEDING
AND        UNBOUNDED FOLLOWING )
FROM        EMPLOYEE2;


Employeeid
DepartmentNo
Salary
Group Max(Salary)
1
100
1000
9000
9
100
9000
9000
5
100
5000
9000
6
200
6000
12345.11
2
200
2000
12345.11
124
200
12345.11
12345.11
10
200
10000
12345.11
3
300
3000
11000
7
300
7000
11000
11
300
11000
11000
4
400
4000
12345.11
8
400
8000
12345.11
12
400
12000
12345.11
144
400
12345.11
12345.11

No comments:

Post a Comment