sql: count unique field values

Trabla: sql: count unique field values

Solving:

... COUNT(  DISTINCT  fieldname ) ....

Example:

mytable:
|country| city            |
|USA    | New York |
|USA    | Odessa      |
|Germany | Berlin    |


SELECT
COUNT( DISTINCT t.country) AS unique_countries_qty,
COUNT( DISTINCT t.city ) AS unique_cities_qty
FROM mytable AS t

No comments:

Post a Comment