指定報表總計的聚總規則

此主題描述明確指定報表總計聚總規則的方式,這有助於改善效能,且專為編寫 Oracle Analytics 報表的技術開發人員所設計。

下圖顯示的範例其報表定義為年度、月份以及客戶區域,且 Count Distinct of Customers with Orders 度量定義為計算訂單的相異客戶。

以下為 GUID-4E9DB43C-F827-4BBB-A94D-5A91F3626C72-default.jpg 的說明
.jpg

邏輯查詢看起來如下:

SELECT
   0 s_0,
   "A - Sample Sales"."Cust Regions"."C50  Region" s_1,
   "A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" s_2,
   REPORT_AGGREGATE("A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" BY ) s_3
FROM "A - Sample Sales"
WHERE
("Time"."T02 Per Name Month" = '2011 / 11')
ORDER BY 2 ASC NULLS LAST
FETCH FIRST 500001 ROWS ONLY

產生的實體查詢看起來如下:

WITH
SAWITH0 AS (select count(distinct T42433.Cust_Key) as c1,
     T42430.Region as c2
from
     BISAMPLE.SAMP_CUSTOMERS_D T42428 /* D60 Customers */ ,
     BISAMPLE.SAMP_ADDRESSES_D T42430 /* D62 Customers Addresses */ ,
     BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ ,
     BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */
where  ( T42405.Mth_Key = T42433.Bill_Mth_Key and T42405.Per_Name_Month = '2011 / 11' and T42428.Cust_Key = T42433.Cust_Key and T42428.Address_Key = T42430.Address_Key )
group by T42430.Region),
SAWITH1 AS (select count(distinct T42433.Cust_Key) as c1
from
     BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ ,
     BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */
where  ( T42405.Per_Name_Month = '2011 / 11' and T42405.Mth_Key = T42433.Bill_Mth_Key ) )
select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4 from ( select D1.c1 as c1,
     D1.c2 as c2,
     D1.c3 as c3,
     D1.c4 as c4
from
     (select 0 as c1,
               D1.c2 as c2,
               D1.c1 as c3,
               D2.c1 as c4,
               ROW_NUMBER() OVER (PARTITION BY D1.c2 ORDER BY D1.c2 ASC) as c5
          from
               SAWITH0 D1,
               SAWITH1 D2
     ) D1
where  ( D1.c5 = 1 )
order by c2 ) D1 where rownum <= 500001

總計值 480 為成員值的總和 (182 + 113 + 185)。計算總計的邏輯查詢表示式為:“REPORT_AGGREGATE("A - Sample Sales"."Counts"."32 # of Cust with Orders (Cnt Distinct)" BY ) s_3”

使用 REPORT_AGGREGATE 時,總計將與成員值分開計算。但針對此報表設計,正確的總計可以從此報表的成員計算而得。

編輯資料欄公式,將 Aggregation Rule (Totals Row)Server Complex Aggregate 變更為 Sum,邏輯和實體 SQL 查詢會隨之變更。

下圖顯示原始聚總。

以下為 GUID-96FB697B-24F7-41A9-8678-F99921E5BB19-default.png 的說明
.png

下圖顯示修改後的聚總。

以下為 GUID-ED289D12-C0BD-4588-B288-2069EAB3EB1D-default.png 的說明
.png

修改後的邏輯 SQL 查詢現在包含 REPORT_SUM

SELECT
   0 s_0,
   "A - Sample Sales"."Cust Regions"."C50  Region" s_1,"A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" s_2,
   REPORT_SUM("A - Sample Sales"."Counts"."32  # of Cust with Orders  (Cnt Distinct)" BY ) s_3
FROM "A - Sample Sales"
WHERE
("Time"."T02 Per Name Month" = '2011 / 11')
ORDER BY 2 ASC NULLS LAST
FETCH FIRST 500001 ROWS ONLY

這是產生的實體查詢:

WITH
SAWITH0 AS (select count(distinct T42433.Cust_Key) as c1,
     T42430.Region as c2
from
     BISAMPLE.SAMP_CUSTOMERS_D T42428 /* D60 Customers */ ,
     BISAMPLE.SAMP_ADDRESSES_D T42430 /* D62 Customers Addresses */ ,
     BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ ,
     BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */
where  ( T42405.Mth_Key = T42433.Bill_Mth_Key and T42405.Per_Name_Month = '2011 / 11' and T42428.Cust_Key = T42433.Cust_Key and T42428.Address_Key = T42430.Address_Key )
group by T42430.Region),
SAWITH1 AS (select 0 as c1,
     D1.c2 as c2,
     D1.c1 as c3
from
     SAWITH0 D1)
select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4 from ( select D1.c1 as c1,
     D1.c2 as c2,
     D1.c3 as c3,
     sum(D1.c3) over ()  as c4
from
     SAWITH1 D1
order by c2 ) D1 where rownum <= 500001

工作簿中提供可明確設定聚總的相同選項。請參閱設定視覺化的數值格式。在這個範例中,Count Distinct Customers with Orders 資料欄的聚總方法變更為總和

請複查您的報表,確認報表使用最佳聚總規則。若報表設計允許,請使用明確聚總規則。

如需報表的詳細資訊,請參閱建立分析。