LAG/LEAD分析函数带IGNORE NULLS是11G新特性,它的效率远远比LAST_VALUE要差:
先构造9999行数据如下:
dingjun123@ORADB> DROP TABLE t;
Table dropped.
dingjun123@ORADB> CREATE TABLE t AS SELECT LEVEL ID,decode(MOD(LEVEL,5),1,'VAL'||LEVEL) val,
2 'CATE'||(trunc((LEVEL-1)/5)) cate FROM dual CONNECT BY LEVEL<10000;
Table created.
dingjun123@ORADB> select count(*) cnt,count(val) cnt_val from t;
CNT CNT_VAL
---------- ----------
9999 2000
1 row selected.