zoukankan      html  css  js  c++  java
  • oracle 分析函数5

    RATIO_TO_REPORT
    
    -- 列出上一年度每个月的销售总额、年底销售额以及每个月的销售额占全年总销售额的比例
    -- 方法①:
    select all_sales.*,
    100 * round(cust_sales / region_sales, 2) || '%' Percent from 
    (select o.cust_nbr customer,o.region_id region,
    sum(o.tot_sales) cust_sales,
    sum(sum(o.tot_sales)) over(partition by o.region_id) region_sales
    from orders_tmp o
    where o.year = 2001 group by o.region_id, o.cust_nbr) all_sales
    where all_sales.cust_sales > all_sales.region_sales * 0.2;
    
    -- 方法②:
    select region_id, salesperson_id, 
    sum(tot_sales) sp_sales,
    round(sum(tot_sales) / sum(sum(tot_sales)) over (partition by region_id), 2) percent_of_region
    from orders where year = 2001
    group by region_id, salesperson_id
    order by region_id, salesperson_id;
    
    -- 方法③
    select region_id, salesperson_id, 
    sum(tot_sales) sp_sales,
    (round(ratio_to_report(sum(tot_sales)) over (partition by region_id), 2)) * 100 || '%' sp_ratio
    from orders_tmp where year = 2001
    group by region_id, salesperson_id
    order by region_id, salesperson_id;
  • 相关阅读:
    python之函数嵌套与闭包
    python之高阶函数
    python之装饰器
    python之内置函数
    python之内置函数:map ,filter ,reduce总结
    Python之reduce函数
    install python2 python3 in same computer
    git basic
    git LF CRLF
    2 thread, first to open chat window, second to make the phone
  • 原文地址:https://www.cnblogs.com/c0liu/p/7400807.html
Copyright © 2011-2022 走看看