Previous | Table of Contents | Next |
Today, you learned a number of ways to produce totals and subtotals in your result sets. You learned how to calculate scalar aggregates yesterday and vector aggregates today. You learned what the CUBE and ROLLUP operators do inside a GROUP BY clause. You also learned how to cull rows from a final result set, using HAVING, without affecting the calculation of the aggregates that produced those rows.
Q What can the WHERE clause do that the HAVING clause cannot?
A The WHERE clause restricts the rows that are used to evaluate a query. If a row cant pass the conditions in the WHERE clause, it is not used in the calculation of an aggregate in the query.
Q What can the HAVING clause do that the WHERE cannot?
A Because HAVING operates on a result set, and not on the rows in tables, an aggregate may appear in a HAVING clause. An aggregate may never appear in a WHERE clause, although it may be part of a subquery that feeds the WHERE. Subqueries are explored on Day 8.
Q Where did CUBE and ROLLUP get their names?
A The CUBE operator calculates superaggregates on all possible combinations of groups and subgroups appearing in the GROUP BY clause. Mathematically, this assemblage of combinations of all possible subgroups forms an n-dimensional cube.
The ROLLUP operator calculates running totals (or maximums, minimums, and so on), which take the previous rows aggregates, and then rolls them up into a new aggregate on its own row.
The Workshop provides quiz questions to help you solidify your understanding of the material covered, as well as exercises to provide you with experience in using what youve learned. Try to understand the quiz and exercise answers before continuing on to the next days lesson. Answers are provided in the appendix.
Previous | Table of Contents | Next |