Previous Topic

Next Topic

Book Contents

Book Index

Summary or Group-by queries

Summary queries (also called Group-By queries) are used to summarise the contents of a table.

There is an important rule about summary queries which you need to be aware of. All columns in the group-by query need to be either:

This is best illustrated with an example. The following query summarizes customer revenue by customer and month:

Select customer_code, month, sum(revenue) from orders group by customer_code, month

In this:

The columns you are summarising by are specified as Group-By columns. In the Query-Column Grid you select these by clicking on the Group-By column.

The columns you are summarizing must have a summary function. This indicates how you are summarizing the column. In the above example, the summary function is sum(). Other functions are: min(), max(), avg(). These can be seen in the Functions drop-down list.

So, the rule for a summary query is that all columns must have either:

When you are doing a summary query you can also specify a Having clause to select the summary rows for your result-set.