|
The Information
Technology Architects |
Oracle Rollup and Cube QueriesMaking the Business Intelligence Process a Little Easier. In the heart of any business intelligence process today, you'll find a data warehouse surrounded by managers and executives who need to retrieve some mission-critical data -- as fast and elaborate as possible. Your challenge as the technology expert at the organization, however, is to achieve the above goal without resorting to any unnecessary steps. Rollup and Cube queries are among the little-known tools that help you do just that. Let's look at a sample table in your data warehouse, as shown by the Oracle Enterprise Manager:
What you're trying to do with this table is to summarize it by CUSTOMER and SALESREP. Your typical GROUP BY query will produce the following results: SQL> select customer, salesrep, sum(extamount) from sales group by customer,salesrep; CUSTOMER SALESREP SUM(EXTAMOUNT) ---------- ---------- -------------- C1 R1 140 C1 R2 230 C2 R1 410 C2 R2 350 With a ROLLUP query, not only you get the same output, but also a summary of total sales amount for each customer: SQL> select customer, salesrep, sum(extamount) from sales group by rollup (customer,salesrep); CUSTOMER SALESREP SUM(EXTAMOUNT) ---------- ---------- -------------- C1 R1 140 C1 R2 230 C1 370 C2 R1 410 C2 R2 350 C2 760 1130 7 rows selected. And finally, with a CUBE query, you get additional summaries in all dimensions of your data: SQL> select customer, salesrep, sum(extamount) from sales group by cube (customer,salesrep); CUSTOMER SALESREP SUM(EXTAMOUNT) ---------- ---------- -------------- C1 R1 140 C1 R2 230 C1 370 C2 R1 410 C2 R2 350 C2 760 R1 550 R2 580 1130 9 rows selected. The beauty of running ROLLUP and CUBE queries is that the result set is ready to be transferred to other destinations, including HTML, XML, or report distribution tools of your choice.
|
Copyright © 2008 Pointer Corporation
|