Use and usage of Oracle lead and LGA Functions

Source: Internet
Author: User

Lead:Returns the value of hire_date in the next record.
Select last_name, hire_date,
Lead (hire_date, 1) over (order by hire_date) as "nexthired"
From employees
Where department_id = 30;

Last_name
Hire_dateNexthired
-------------------------------------------
Raphaely
07-dec-9418-may-95

Khoo
18-may-95
24-jul-97
Tobias
24-jul-97
24-dec-97
Baida 
24-dec-97
15-nov-98
Himuro
15-nov-98
10-aug-99
Colmenares
10-aug-99

Lag:Returns the value of hire_date in the previous record (if not, the value is 0 ).
Select last_name, hire_date, salary,
Lag (salary, 1, 0) over (order by hire_date) as prev_sal
From employees
Where job_id = 'pu _ cler ';


Last_name
Hire_date
SalaryPrev_sal
------------------------------------------------------

Khoo
18-may-95

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.