Vous êtes sur la page 1sur 98

Example 3

If you ran the report in Example 2 using SELECT... COUNT


without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
sults

without grouping the re

by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a

department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the


statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).

Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department

(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;

The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.

Chapter 8: Aggregate Functions


COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229

Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.

Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21

Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of

the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee

WHERE sex = 'M' ;


The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)

---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5

In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.

SELECT deptno, COUNT(deptno)


FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno

ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)

------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3

500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3

Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6

Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
sults

without grouping the re

by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a

department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the


statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).

Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department

(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;

The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.

Chapter 8: Aggregate Functions


COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229

Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.

Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21

Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of

the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee

WHERE sex = 'M' ;


The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)

---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5

In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.

SELECT deptno, COUNT(deptno)


FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno

ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)

------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3

500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3

Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6

Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
sults

without grouping the re

by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a

department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the


statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).

Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department

(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;

The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.

Chapter 8: Aggregate Functions


COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229

Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.

Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21

Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of

the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee

WHERE sex = 'M' ;


The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)

---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5

In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.

SELECT deptno, COUNT(deptno)


FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno

ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)

------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3

500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3

Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6

Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
sults

without grouping the re

by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a

department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the


statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).

Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department

(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;

The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.

Chapter 8: Aggregate Functions


COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229

Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.

Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21

Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of

the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee

WHERE sex = 'M' ;


The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)

---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5

In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.

SELECT deptno, COUNT(deptno)


FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno

ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)

------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3

500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3

Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6

Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
sults

without grouping the re

by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a

department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the


statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).

Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department

(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;

The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.

Chapter 8: Aggregate Functions


COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229

Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.

Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21

Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of

the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee

WHERE sex = 'M' ;


The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)

---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5

In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.

SELECT deptno, COUNT(deptno)


FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno

ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)

------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3

500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3

Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6

Example 3
If you ran the report in Example 2 using SELECT... COUNT
without grouping the re
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
If you ran the report in Example 2 using SELECT... COUNT
sults

without grouping the re

by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a
department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the
statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6
Example 3
without grouping the re
If you ran the report in Example 2 using SELECT... COUNT
sults
by department number, the results table would have only registered non-null occu
rrences of
DeptNo and would not have included the two employees not yet assigned to a

department(nulls). The counts differ (23 in Example 2 as opposed to 21 using the


statement
documented in this example).
Recall that in addition to the 21 employees in the Employee table who are assign
ed to a
department, there are two new employees who are not yet assigned to a department
(the row
for each new employee has a null department number).
SELECT COUNT(deptno) FROM employee ;
The result of this SELECT is that COUNT returns a total of the non-null occurren
ces of
department number.
Chapter 8: Aggregate Functions
COUNT
SQL Functions, Operators, Expressions, and Predicates 229
Because aggregate functions ignore nulls, the two new employees are not reflecte
d in the
figure.
Count(DeptNo)
-------------21
Example 4
This example uses COUNT to provide the number of male employees in the Employee
table of
the database.
SELECT COUNT(sex)
FROM Employee
WHERE sex = 'M' ;
The result is as follows.
Count(Sex)
---------12
Example 5
In this example COUNT provides, for each department, a total of the rows that ha
ve non-null
department numbers.
SELECT deptno, COUNT(deptno)
FROM employee
GROUP BY deptno
ORDER BY deptno ;
Notice once again that the two new employees are not included in the count.
DeptNo Count(DeptNo)
------ ------------100 4
300 3
500 7
600 4
700 3
Example 6