rownum和分析函数 over

select rownum, t.* from qyuser.tr_apply_info t where rownum < 10;

--rownum 对于满足 查询条件的结果,从1 开始,所以大于1不行
select z.* from (select t.*, rownum from qyuser.tr_apply_info t where rownum > 10 and rownum < 20) z;

select * from (select rownum rn,t.*from qyuser.tr_apply_info t where rownum <20) where rn >10;

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;

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;

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;

select t.name, t.class, t.sroce, avg(t.sroce) over(partition by t.class order by t.sroce ) from t2_temp t;

转载于:https://www.cnblogs.com/wuer888/p/10683314.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值