Databases Reference
In-Depth Information
The query results appear in Figure 3-33.
90
Within credit limit,
customers are
sorted by name
Customers are
sorted by credit limit
in descending order
FIGURE 3-33 Query results
BUILT-IN FUNCTIONS
SQL has built-in functions (also called aggregate functions) to calculate the number of entries, the sum or
average of all the entries in a given column, and the largest or smallest values in a given column. In SQL, these
functions are called COUNT, SUM, AVG, MAX, and MIN, respectively.
EXAMPLE 18
How many parts are in item class HW?
In this query, you want to count the number of rows in the query results that have the value HW in the
Class field. You could count the number of part numbers in the query results or the number of descriptions or
the number of entries in any other field. It doesn't matter which column you choose because all columns will
yield the correct answer. Rather than requiring you to pick a column arbitrarily, some versions of SQL allow
you to use the * symbol to select any column. In SQL versions that support the * symbol, you could use the
query design shown in Figure 3-34.
COUNT function
Co ndition to select
records in the HW
item class
FIGURE 3-34 SQL query to count records
 
 
Search WWH ::




Custom Search