Use and usage of Oracle lead and LGA two functions

Source: Internet
Author: User
Lead: Returns the value of the next record hire_date.
SELECT last_name, Hire_date,
Leads (hire_date, 1) over (order by hire_date) as "nexthired"
From Employees
WHERE department_id = 30;

Last_Name hire_date nexthired
-------------------------  ---------  ---------
raphaely 07-dec-94 18-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 the previous record hire_date (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_clerk ';


Last_Name hire_date SALARY Prev_sal
-------------------------  ---------  ----------  ----------
khoo                                            18-may-95              3100      &NB Sp
Related Article

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.