You can eliminate duplicate rows when using SUM, AVG, and COUNT by using DISTINCT. This causes the duplicate rows to be eliminated before the aggregate function is applied.
Using DISTINCT
If you use DISTINCT, you must name a column explicitly; you cannot use an arithmetic expression.
How It's Done
Put DISTINCT immediately before the column name.
Count the number of communities represented by the employees at Commonwealth Auto by entering:
select count(distinct city)
from employee;
The result looks like this:
(EXPR) ------ 13 1 row processed
|
Copyright © 2014 CA.
All rights reserved.
|
|