MySQL: Count unique pairs of values in rows

前端 未结 1 1690
离开以前
离开以前 2021-01-17 00:34

I\'m stuck with a problem I don\'t know how to solve. Here\'s what my table \'myTable\' look like:

+----------+-------------+------+-----+---------+---------         


        
相关标签:
1条回答
  • 2021-01-17 00:50

    As you need to count distinct name you need to use distinct keyword.

    Try this query

    select 
       one,  
       count(distinct two) as cnt 
    from 
       tbl 
    group by 
       one
    

    SQL FIDDLE

    |   ONE | CNT |
    ---------------
    |   cat |   2 |
    |   dog |   3 |
    | mouse |   1 |
    
    0 讨论(0)
提交回复
热议问题