Oracle Reporting 3 - Aggregation Level
To determine the aggregation level in a report, Oracle provides grouping_id and group_id functions.
Grouping_ID:GROUPING_ID returns a single number that enables you to determine the exact GROUP BY level. For each row, GROUPING_ID takes the set of 1's and 0's that would be generated if you used the appropriate GROUPING functions and concatenates them, forming a bit vector. The bit vector is treated as a binary number, and the number's base-10 value is
returned by the GROUPING_ID function. For instance, if you group with the expression CUBE(a, b) the possible values are as follows:
select deptno, job, sum(sal), grouping_id(deptno, job)
from emp
group by cube(deptno, job)
order by deptno nulls last;
Group_ID: The GROUP_ID function lets you distinguish among duplicate groupings. If there are multiple sets of rows calculated for a given level, GROUP_ID assigns the value of 0 to all the rows in the first set. All other sets of duplicate rows for a particular grouping are assigned higher values, starting with 1.
SELECT country_iso_code, SUBSTR(cust_state_province,1,12), SUM(amount_sold),
GROUPING_ID(country_iso_code, cust_state_province) GROUPING_ID, GROUP_ID()
FROM sales, customers, times, countries
WHERE sales.time_id=times.time_id AND sales.cust_id=customers.cust_id
AND customers.country_id=countries.country_id AND times.time_id= '30-OCT-00'
AND country_iso_code IN ('FR', 'ES')
GROUP BY GROUPING SETS (country_iso_code,
ROLLUP(country_iso_code, cust_state_province));
Groupings: (country_id, cust_state_province), (country_id), (country_id), and ().
You can filter out duplicate (region) groupings from the previous example by adding a HAVING clause condition GROUP_ID()=0 to the query.
Grouping_ID:GROUPING_ID returns a single number that enables you to determine the exact GROUP BY level. For each row, GROUPING_ID takes the set of 1's and 0's that would be generated if you used the appropriate GROUPING functions and concatenates them, forming a bit vector. The bit vector is treated as a binary number, and the number's base-10 value is
returned by the GROUPING_ID function. For instance, if you group with the expression CUBE(a, b) the possible values are as follows:
select deptno, job, sum(sal), grouping_id(deptno, job)
from emp
group by cube(deptno, job)
order by deptno nulls last;
Group_ID: The GROUP_ID function lets you distinguish among duplicate groupings. If there are multiple sets of rows calculated for a given level, GROUP_ID assigns the value of 0 to all the rows in the first set. All other sets of duplicate rows for a particular grouping are assigned higher values, starting with 1.
SELECT country_iso_code, SUBSTR(cust_state_province,1,12), SUM(amount_sold),
GROUPING_ID(country_iso_code, cust_state_province) GROUPING_ID, GROUP_ID()
FROM sales, customers, times, countries
WHERE sales.time_id=times.time_id AND sales.cust_id=customers.cust_id
AND customers.country_id=countries.country_id AND times.time_id= '30-OCT-00'
AND country_iso_code IN ('FR', 'ES')
GROUP BY GROUPING SETS (country_iso_code,
ROLLUP(country_iso_code, cust_state_province));
Groupings: (country_id, cust_state_province), (country_id), (country_id), and ().
You can filter out duplicate (region) groupings from the previous example by adding a HAVING clause condition GROUP_ID()=0 to the query.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/638844/viewspace-1061063/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle Reporting 6 - ModelOracle
- Oracle Reporting 5 - WindowingOracle
- Oracle Reporting 7 - Model ExamplesOracle
- Oracle level偽列Oracle
- Oracle statistic_levelOracle
- Oracle Reporting 2 - Subtotals and Grand TotalOracle
- Oracle Reporting 4 - Time Series CalculationsOracle
- Oracle Reporting 1 - Ratio_to_Report FunctionOracleFunction
- Oracle的隔離級別(Isolation Level)Oracle
- oracle event 10046 level_事件Oracle事件
- ORACLE 字串聚合函式 string varchar2 aggregation functionOracle字串函式Function
- Error reporting for dbusError
- zt_dbanotes_Oracle Trace Level Event NumbersOracle
- MongoDB 新手入門 - AggregationMongoDB
- 翻譯(九)——Clustered Indexes: Stairway to SQL Server Indexes Level 3IndexAISQLServer
- DOM Level 3 Events: DOM事件架構(2-1)事件架構
- DOM Level 3 Events: DOM事件架構(2-2)事件架構
- Oracle Appliactions 11i concepts(十五) - Multiple Reporting CurrenciesOracleAPP
- Django 中 Aggregation聚合的使用Django
- Basic Aggregation in MongoDB 2.1 with PythonMongoDBPython
- error_reporting()的用法Error
- 懂你英語 Level4-Unit 3 3/4 vocabulary 商品、服務和工作
- oracle事務隔離級別transaction isolation level初識Oracle
- MongoDB系列--深入理解MongoDB聚合(Aggregation )MongoDB
- 2_深入解析Oracle ASSM結構之Level 2 Bitmap BlockOracleSSMBloC
- [Rman]Oracle Rman增量備份Level012指令碼Oracle指令碼
- Oracle OCP 1Z0 053 Q259(STATISTICS_LEVEL)Oracle
- 懂你英語level4 unit3 part1 Political terms
- 記一次kafka的high level和low levelKafka
- natas(level0-level14)通關詳細指南(一)
- transaction-level or statement-level consistency; check constraintsAI
- 擴充套件部署(Reporting Services 配置)套件
- Improve reporting with duplicate server-idsServer
- CSS LEVEL4CSS
- Oracle 標準審計,設定AUDIT_SYSLOG _LEVEL引數Oracle
- PostgreSQL DBA(62) - PG 12 More progress reportingSQL
- 英語流利說懂你英語 Level5 Unit3 Part3 Vocabulary - Describing Actions
- Lode Runner 2 Credits Level