IBM Books

SQL Getting Started


Complex Queries

DB2 Universal Database allows you to group, consolidate, and view multiple columns in a single result set through the use of ROLLUP and CUBE. This new and powerful capability enhances and simplifies SQL based data analysis.

There are various methods of extracting useful information from the database. You can implement recursive queries to produce result tables from existing data sets.

ROLLUP and CUBE Queries

You specify ROLLUP and CUBE operations in the GROUP BY clause of a query. ROLLUP grouping produces a result set containing the regular grouped rows and sub-total rows. CUBE grouping produces a result set containing the rows from ROLLUP and cross-tabulation rows. So for ROLLUP, you can get the sales by person by month with monthly sales totals and an overall total. For CUBE, additional rows would be included for total sales by person. See the SQL Reference for further details.

Recursive Queries

A recursive query is a query that iteratively uses result data to determine further results. You might think of this as traversing a tree or a graph. Practical examples where this is useful include bill of materials applications, reservation systems, network planning and scheduling. A recursive query is written using a common table expression that includes a reference to its own name. See the SQL Reference for examples of recursive queries.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]