Using an aggregate function, you can create a summary for all the values in a table. For example, you can create a query such as the following to display the total price for all books in the titles
table:
SELECT SUM(price)
FROM titles
You can create multiple summaries in the same query by using aggregate functions with more than one column. For example, you can create a query that calculates the total of the price
column and the average of the discount
column.
You can also summarize the same column in different ways (such as totaling, counting, and averaging) in the same query. For example, the following query averages and summarizes the price
column from the titles
table:
SELECT AVG(price), SUM(price)
FROM titles
If you add a search condition, you can summarize the subset of rows that meet that condition.
Note You can also count all the rows in the table or the ones that meet a specific condition. For details, see Counting Rows in a Table.
When you create a single summary value for all rows in a table, you display only the summaries themselves. For example, if you are totaling the value of the price
column of the titles
table, you would not also display individual titles, publisher names, and so on.
Note If you are subtotaling — that is, creating groups — you can display column values for each group. For details, see Grouping Rows in Query Results.
To summarize values for all rows
The Query Designer automatically assigns a column alias to the column you are summarizing to create a useful column heading in query output. For more details, see Creating Column Aliases.
Note Oracle supports additional aggregate functions. For details, see Query Designer Considerations for Oracle Databases.
The Query Designer replaces the column name in the statement in the SQL pane with the aggregate function that you specify. For example, the SQL statement might look like this:
SELECT SUM(price)
FROM titles
When you add another column to the query output list or order by list, the Query Designer automatically fills the term Group By into the Group By column of the grid. Select the appropriate aggregate function.
When you execute the query, the Results pane displays the summaries that you specified.
Note The Query Designer maintains aggregate functions as part of the SQL statement in the SQL pane until you explicitly turn off Group By mode. Therefore, if you modify your query by changing input sources or changing its type, the resulting query might include invalid aggregate functions.