The DISTINCT keyword is optional with SUM, AVG, and COUNT. When you use DISTINCT, duplicate values are eliminated before calculating the sum, average, or count. For example, to find the number of different cities in which there are contacts, execute the following statement:
SELECT COUNT( DISTINCT City ) FROM Contacts; |
COUNT( DISTINCT Contacts.City) |
---|
16 |
You can use more than one aggregate function with DISTINCT in a query. Each DISTINCT is evaluated independently. For example:
SELECT COUNT( DISTINCT GivenName ) "first names", COUNT( DISTINCT Surname ) "last names" FROM Contacts; |
first names | last names |
---|---|
48 | 60 |
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |