• 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;

  • 相关阅读:
    树莓派pwm驱动好盈电调及伺服电机
    wiringPi库的pwm配置及使用说明
    未能加载文件或程序集“**, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。
    poj 1700 Crossing River(贪心)
    前缀 树 背单词(Remember the Word,LA 3942)
    c/c++ double的数字 转成字符串后 可以有效的避免精度要求不高的数
    hdu acm 2154(多解取一解)
    hdu 5104 Primes Problem(prime 将三重循环化两重)
    hdu 2203亲和串 (kmp)
    hdu 2519 新生晚会 排列组合
  • 原文地址:https://www.cnblogs.com/wuer888/p/10683314.html
Copyright © 2020-2023  润新知