select min(name) as first, max(name) as last
from STUDENTS;
This query yields the table:
FIRSTLAST
---------------- --------------
Edwards P. David Rawlings Jerry
Next, we show a select construct where the same functions are applied to
a numerical domain:
select min(grade) as lowgr,
max(grade) as highgr from GRADES
where stno = ’1011’;
This generates the answer:
LOWGRHIGHGR
-----------------
4090
The query
select avg(distinct grade) as avggr from GRADES
where stno = ’1011’
returns the table
AVGGR
-----
73.75
If we discard duplicate values as in
select avg(distinct grade) as avggr from GRADES
where stno = ’1011’
then the average grade is lower, indicating a preponderance of the higher grades
for this student:
AVGGR
-----
68.33
Built-in functions can be used in subqueries. This is illustrated by the next
example.
Example 5.15.3 To retrieve the students who obtained a grade higher than
the average grade in cs110 we write: