Count(distinct case when)

    distinct count query in sql
    count distinct statement in sql
    is count distinct in sql
    distinct count sql server
  • Distinct count query in sql
  • Count distinct excel.

    Sql distinct count group by

  • Select distinct on one column, with multiple columns returned sql
  • Count distinct excel
  • Count(distinct *)
  • Sql count unique values in column
  • Problem

    You’d like to count how many different non-NULL values there are in a given column.

    Example

    Our database has a table named with data in the following columns: , , , and .

    idfirst_namelast_namecity
    1JohnWilliamsChicago
    2TomBrownAustin
    3LucyMillerChicago
    4EllieSmithDallas
    5BrianJonesAustin
    6AllanDavisNULL

    Let’s find the number of different (and non-) cities.

    Solution

    SELECT COUNT(DISTINCT city) as cities FROM customer;

    This query returns number of cities where customers live:

    Discussion

    To count the number of different values that are stored in a given column, you simply need to designate the column you pass in to the function as .

    When given a column, returns the number of values in that column. Combining this with returns only the number of unique (and non-NULL) values.

    Recommended courses:

    Recommended articles:

    See also:

      sql count distinct count