Oracle Lead use Practice __oracle

Source: Internet
Author: User
Tags lzf

If I hadn't used the Oracle lead this time, I wouldn't have found anything so useful.

Oracle statistical analysis function lead

Syntax structure:

Leads (value_expr [, Offset][,default]) over ([Query_partition_clause] ORDER by Order_by_clause)

Parameter description:

The value_expr value expression, usually a field, is also an expression. The value_expr itself does not support analytic functions, which means that the lead does not support multi-tier calls.
Offset offsets, should be familiar with mathematical concepts, or relative offset, the table to open the current line of offset line, if offset is an integer to indicate the order of the first n rows, if the negative number is the next nth line. If this argument is not provided, the default is 1.
Default defaults, if not found, what should return the meaning of the value, somewhat similar to NVL (Col,value). If it is not set and cannot be found, it returns null
Over can be simply translated into what ... Based on
The Query_partition_clause partition statement, the statement that partitions the result set, is optional, if not all of one partition.
The Order_by_clause sort statement must be required, as ordered by xxx Desc/asc

Explanation Example:
Sql> select * from Test_value;

Mons JJR CJL Cjje
---------- ---------- ---------- ----------
200801 LZF 250 1999
200802 LZF 200 2000
200803 LZF 300 1000
200804 LZF 23 189
200805 LZF 356 456
200806 LZF 100 200
200807 LZF 600 700
200808 LZF 23 123
200809 LZF 400 500

9 Rows selected

Sql>
Sql> Select rownum serial number, MONS,CJL cjl_01,
2 Leads (cjl,1) over (order by Mons Desc) cjl_02,
3 Leads (cjl,2) over (order by Mons Desc) cjl_03,
4 Leads (cjl,3) over (order by Mons Desc) Cjl_04,
5 Leads (cjl,4) over (order by Mons Desc) cjl_05,
6 leads (cjl,5) over (order by Mons Desc) cjl_06,
7 leads (cjl,6) over (order by Mons Desc) cjl_07,
8 Leads (cjl,7) over (order by Mons Desc) cjl_08,
9 Lead (cjl,8) over (order by Mons Desc) cjl_09
Ten from Test_value

Serial number Mons cjl_01 cjl_02 cjl_03 cjl_04 cjl_05 cjl_06 cjl_07 cjl_08 cjl_09
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
9 200809 400 23 600 100 356 23 300 200 250
8 200808 23 600 100 356 23 300 200 250
7 200807 600 100 356 23 300 200 250
6 200806 100 356 23 300 200 250
5 200805 356 23 300 200 250
4 200804 23 300 200 250
3 200803 300 200 250
2 200802 200 250
1 200801 250

Practice Usage Examples:

Select Id,lead (id,1) over (partition by call_req_id order by call_req_id, IDS), Type,analyst,time_stamp from Act_log call_req_id, ID

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.