last_value over range between : First Last Value « Analytical Functions « Oracle PL / SQL

Home
Oracle PL / SQL
1.Aggregate Functions
2.Analytical Functions
3.Char Functions
4.Constraints
5.Conversion Functions
6.Cursor
7.Data Type
8.Date Timezone
9.Hierarchical Query
10.Index
11.Insert Delete Update
12.Large Objects
13.Numeric Math Functions
14.Object Oriented Database
15.PL SQL
16.Regular Expressions
17.Report Column Page
18.Result Set
19.Select Query
20.Sequence
21.SQL Plus
22.Stored Procedure Function
23.Subquery
24.System Packages
25.System Tables Views
26.Table
27.Table Joins
28.Trigger
29.User Previliege
30.View
31.XML
Oracle PL / SQL » Analytical Functions » First Last Value 




last_value over range between
 


create table employee(
         emp_no                 integer         primary key
        ,lastname               varchar2(20)    not null
        ,hiredate               date
        ,salary                 integer
);

insert into employee(emp_no, lastname, hiredate,salary)
             values (1,'Nancy','1-feb-1999',12);

insert into employee(emp_no, lastname, hiredate,salary)
             values (2,'Joey','1-feb-2000',13);

insert into employee(emp_no, lastname, hiredate,salary)
             values (3,'Goldy','1-feb-2001',14);

insert into employee(emp_no, lastname, hiredate,salary)
             values (4,'Bluey','1-feb-2002',15);

select lastname , hiredate, salary,
    avg(salaryover (order by hiredate
                      range between 182 preceding and 182 followingavg_sal,
    last_value(lastnameover (order by hiredate
                      range between 182 preceding and 182 followingwindow_bottom
from employee
order by hiredate asc;


LASTNAME             HIREDATE      SALARY    AVG_SAL WINDOW_BOTTOM       
-------------------- --------- ---------- ---------- --------------------
Nancy                01-FEB-99         12         12 Nancy               
Joey                 01-FEB-00         13         13 Joey                
Goldy                01-FEB-01         14         14 Goldy               
Bluey                01-FEB-02         15         15 Bluey  

drop table employee;


 














Related examples in the same category
1.FIRST_VALUE and LAST_VALUE: which rows are used in the calculation of the window function for each row
2.first_value over partition
3.FIRST_VALUE() get the first rows in a window
4.LAST_VALUE(): get the last rows in a window
5.The query divides the current month’s sales amount by the previous month’s sales amount
6.last_value over range
7.Avg over, first_value over
8.first_value over order by
9.first_value over order by range
10.first_value over order by rows
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.