sql - How range queries identified attribute name in analytic function oracle? -
prototype of range windows defined below
function( ) on (partition <expr1> order <expr2> range between <start_expr> , <end_expr>) or function( ) on (partition <expr1> order <expr2> range [<start_expr> preceding or unbounded preceding]
it's not mentioned range given attributes(x) how parser/evaluation engine identifies attributes(x) .
select deptno, empno, sal, count(*) on (partition deptno order sal range between unbounded preceding , (sal/2) preceding) cnt_lt_half, count(*) on (partition deptno order sal range between (sal/2) following , unbounded following) cnt_mt_half emp order deptno, sal;
in above sql query range applied on employee salary .how parser/evaluation engine identifies range given sal. since no mentioned sal between value .
partition deptno
defines groups
order sal
defines order of rows in each group
range between [start] , [end]
defines a window each row in each group. cannot specify clause unless have specified order by. window boundaries defined range clause let specify 1 expression in order by.
range
specifies window logical offset. looks @ order expression(s) determine window.
in example range
set each row. each row determines rows used analytic function. these rows begining of group max row having salary <= salary of current row (as can see impossible determine without order by, that's why windowing clause requires ordering).
id depno sal 1 1 5 2 1 6 3 1 10 4 2 1 5 2 2 6 2 5 7 2 6
for row id = 6 window
id depno sal 4 2 1 -- unbounded preceding (start first row in group: depno = 2) 5 2 2 -- row has salary < salary of row id=6 (2 < 5/2)
Comments
Post a Comment