Oracle Analytics function Lag lead

Source: Internet
Author: User

LAGis an analytic function. IT provides access to more than one row of a table in the same time without a self join. Given a series of rows returned from a query and a position of the cursor, LAG provides access to a row at a Given physi Cal offset prior to that position.

offsetfor the optional argument, specify a integer is greater than zero. If you don't specify, then its offset default is 1. The optional default value is returned if the offset goes beyond the scope of the window. If you don't specify, then its default default is null.

{ RESPECT | IGNORE } NULLS Determines whether null values of is value_expr included in or eliminated from the calculation. The default is RESPECT NULLS .

You cannot nest analytic functions by using the or any other LAG analytic function for value_expr . However, you can use the other built-in function expressions for value_expr .

For example, there is a requirement, sorted by employee number. Shows how much of the previous SAL is for each employee's Sal.

SELECT Empno,ename, Sal, LAG (sal,1,sal) over (ORDER by empno) as LaStone from EMP

Results

1 7369 SMITH 800.00 800
27499allen1600.00800
37521ward1250.001600
47566jones2975.001250
57654martin1250.002975
67698blake2850.001250
77782clark2450.002850
87788scott3000.002450
97839king5000.003000
107844turner1500.005000
117876adams1100.001500
127900james950.001100
137902ford3000.00950
147934miller1300.003000

The lead is the next, such as lag

Oracle Analytics function Lag lead

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.