Previous Topic: Exercise 5-1Next Topic: Exercise 5-3


Exercise 5-2

Using WHERE

Use the BENEFITS table to write a SELECT statement to display the average vacation accrued in fiscal year 1999 for all employees in Commonwealth Auto. The Human Resources department needs this information for statistical purposes.

The result looks like this:

                          (EXPR)                           ------                           121.01 1 row processed

If your results do not match what you see above, check Review Answers for Chapter 5 for the correct SQL syntax.

COUNT

Use the aggregate function COUNT to count the number of rows in a table.

You use an asterisk in parentheses after COUNT when you want all rows to be counted. You use a column name in parentheses after COUNT when you want all rows with a value in that column to be counted.

How It's Done

Human Resources needs a total count of employees working at Commonwealth Auto. To find this number, enter:

select count(*)
       from employee;

The result looks like this:

     (EXPR)      ------          55 1 row processed

Every row in the EMPLOYEE table was counted.