Databases Reference
In-Depth Information
MIN and MAX You can also find the minimum or maximum of a set of attribute
values. Consider the following query:
''What is the largest number of units of Product Number 21765 that any
individual salesperson has sold?''
Using the MAX operator, you would write:
SELECT MAX(QUANTITY)
FROM SALES
WHERE PRODNUM=21765;
and the result would be:
MAX(QUANTITY)
3110
To find the smallest number of units you simply replace MAX with MIN:
SELECT MIN(QUANTITY)
FROM SALES
WHERE PRODNUM=21765;
and get:
MIN(QUANTITY)
809
COUNT COUNT is a very useful operator that counts the number of rows that
satisfy a set of criteria. It is often used in the context of ''how many of something''
meet some stated conditions. Consider the following query:
''How many salespersons have sold Product Number 21765?''
Remember that each row of the SALES table describes the history of a particular
salesperson selling a particular product. That is, each combination of SPNUM
and PRODNUM is unique; there can only be one row that involves a particular
SPNUM/PRODNUM combination. If you can count the number of rows of that
table that involve Product Number 21765, then you know how many salespersons
have a history of selling it. Using the notational device COUNT(*), the SELECT
statement is:
SELECT COUNT(*)
FROM SALES
WHERE PRODNUM=21765;
and the answer is:
COUNT(*)
3
Search WWH ::




Custom Search