ASA SQL User's Guide
Summarizing, Grouping and Sorting Query Results
Summarizing query results using aggregate functions
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, type:
SELECT count(DISTINCT city) FROM contact
count(distinct contact.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 first_name ) "first names", count( DISTINCT last_name ) "last names" FROM contact
first names | last names |
---|---|
48 | 60 |