SQL to find the number of distinct values in a column

前端 未结 11 1038
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 00:19

I can select all the distinct values in a column in the following ways:

  • SELECT DISTINCT column_name FROM table_name;
  • SELECT column_
11条回答
  •  爱一瞬间的悲伤
    2020-11-28 01:21

    This will give you BOTH the distinct column values and the count of each value. I usually find that I want to know both pieces of information.

    SELECT [columnName], count([columnName]) AS CountOf
    FROM [tableName]
    GROUP BY [columnName]
    

提交回复
热议问题