Oracle analytic Functions-first_value () and Last_value ()

Source: Internet
Author: User

The literal meaning of First_value () and Last_value () is intuitive, taking the values of the records.
Example: Query department The earliest occurrence of sales record date and recent sales record date

Select        dept_id      , Sale_date      , Goods_type      , sale_cnt      over byorder  by sale_date) First_value      throughorderbydesc ) Last_value from Criss_sales;

Look at the results first_value () very intuitive, no more explanation
However, Last_value () value, department D01 should not be for 2014/6/12, department D02 should not be 2014/5/2? Why is every record different?
You can understand this: Last_value () The default statistic range is rows between unbounded preceding and current row
Verify that:

Selectdept_id, Sale_date, Goods_type, sale_cnt, First_value (sale_date) Over(Partition bydept_idOrder  bysale_date) First_value, Last_value (sale_date) Over(Partition bydept_idOrder  bySale_datedesc) Last_value, Last_value (sale_date) Over(Partition bydept_idOrder  bySale_date rowsbetweenunbounded preceding andunbounded following) Last_value_all fromCriss_sales;

The Last_value () value obtained in the case of full statistics, department D01 for 2014/6/12, department D02 for 2014/5/2.

Oracle analytic Functions-first_value () and Last_value ()

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.