select rownum, t.* from qyuser.tr_apply_info t where rownum < 10;sql
--rownum 對於知足 查詢條件的結果,從1 開始,因此大於1不行
select z.* from (select t.*, rownum from qyuser.tr_apply_info t where rownum > 10 and rownum < 20) z;oracle
select * from (select rownum rn,t.*from qyuser.tr_apply_info t where rownum <20) where rn >10;app
SELECT * FROM (select rownum rn, t.* from qyuser.tr_apply_info t where rownum < 20) where rn > 10;
--rownum sql執行順序:
--where group by having rownum order by
--默認rownum在order by以前,因此排序放到rownum以前執行
--內部rownum 須要重命名,不然外部列重名
select * from
( select rownum rn, tt.* from
(select * from qyuser.tr_apply_info t order by t.apply_id desc) tt
where rownum <= 20) where rn >10;函數
--oracle分析函數
--rank跳躍排序 1 1 3 4 4 6
select rank() over(partition by channel_type order by channel_id desc) rank ,t.* from qyuser.tr_channel t ;
select t.channel_type, t.channel_id,dense_rank() over(partition by channel_type order by channel_id desc) rank from qyuser.tr_channel t ;
-- row_number
select t.prod_name,prod_mode , prod_price ,row_number() over(partition by prod_mode order by prod_price desc) rank from qyuser.tr_product t
--dense_rank順序排序 1 1 2 3 3 4
select t.prod_name,prod_mode , prod_price ,dense_rank() over(partition by prod_mode order by t. desc) rank from qyuser.tr_product t
--每組每行 累計求和
select t.name, t.class, t.sroce, sum(t.sroce) over(partition by t.class order by sroce desc) mm from t2_temp t;排序
select t.name,t.class,t.sroce,sum(t.sroce) over(partition by t.class order by t.sroce desc) mm from T2_TEMP t;it
select t.name, t.class, t.sroce, first_value(t.sroce) over(partition by t.class order by t.sroce desc) from t2_temp t;
select t.name, t.class, t.sroce, min(t.sroce) over(partition by t.class order by t.sroce ) from t2_temp t;io
select t.name, t.class, t.sroce, count(t.sroce) over(partition by t.class order by t.sroce ) from t2_temp t;
select t.name, t.class, t.sroce, count(t.name) over(partition by t.class order by t.sroce ) from t2_temp t;class
select t.name, t.class, t.sroce, avg(t.sroce) over(partition by t.class order by t.sroce ) from t2_temp t;select