oracle开发报告功能
首先,回顾oracle开发窗口函数中的整个统计部分,我们使用Oracle提供:复制代码如下:金额(金额(tot_sales))在(月行之间无界之前和顺序)
把全年的订单总金额,该函数将执行一次每个记录在记录集的形成过程中,它是执行了12次。这是很time-consuming.in的事实,我们有一个更方便的方法:
复制代码代码如下:sql选择月份,
和(tot_sales)month_sales,
金额(金额(tot_sales))在(以月)
无界之前和无界以下行之间)win_sales,
金额(金额(tot_sales))在()rpt_sales
从订单
按月分组;
月month_sales window_sales report_sales
---------------------------------------------
16106976307766 6307766
24286766307766 6307766
36370316307766 6307766
45411466307766 6307766
55929356307766 6307766
65014856307766 6307766
76069146307766 6307766
84605206307766 6307766
93928986307766 6307766
105101176307766 6307766
115328896307766 6307766
124924586307766 6307766
已经选了12行。
该功能的空括号表示记录集的所有记录应纳入统计范围。如果使用分区,首先对分区进行分区,然后依次计算分区。
二,ratio_to_report功能:
报告功能的特殊(窗函数)是特别适合的情况下,详细的数据和统计数据需要在报告中同时显示。例如,在销售报告中经常出现这样的需求:表的销量,年底的销售与上年全年的销售每月的百分比。
方法:
复制代码代码如下:选择all_sales *,
100轮(cust_sales / region_sales,2)| | %
从o.cust_nbr(选择客户,
o.region_id区,
和(o.tot_sales)cust_sales,
金额(金额(o.tot_sales))在(分区o.region_id)region_sales
从orders_tmp O
在o.year = 2001
集团通过o.region_id,o.cust_nbr)all_sales
在all_sales.cust_sales > all_sales.region_sales * 0.2;
这是一种愚蠢的方法,也是最容易理解的方法。
方法:
复制代码如下:选择region_id,salesperson_id,
和(tot_sales)sp_sales,
圆(SUM(tot_sales)/金额(金额(tot_sales))
在(分区region_id),2)percent_of_region
从订单
凡年= 2001
集团通过region_id,salesperson_id
为了region_id,salesperson_id;
方法3
复制代码如下:选择region_id,salesperson_id,
和(tot_sales)sp_sales,
圆(ratio_to_report(sum(tot_sales))
在(分区region_id),2)sp_ratio
从订单
凡年= 2001
集团通过region_id,salesperson_id
为了region_id,salesperson_id;
The Ratio_to_report function provided by Oracle allows us to calculate the proportion of each record in its corresponding record set or its subsets.
以上是完整的使用oracle报表功能的内容,希望能给大家一个参考,同时也希望大家多多支持。