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 ()