Retrieve Unique Values and Counts For Each

前端 未结 2 464
忘掉有多难
忘掉有多难 2021-02-04 03:47

Is there a simple way to retrieve a list of all unique values in a column, along with how many times that value appeared?

Example dataset:

A
A
A
B
B
C


        
相关标签:
2条回答
  • 2021-02-04 04:28

    Use GROUP BY:

    select value, count(*) from table group by value
    

    Use HAVING to further reduce the results, e.g. only values that occur more than 3 times:

    select value, count(*) from table group by value having count(*) > 3
    
    0 讨论(0)
  • 2021-02-04 04:34
    SELECT id,COUNT(*) FROM file GROUP BY id
    
    0 讨论(0)
提交回复
热议问题