How to count rows that have the same values in two columns (SQL)?

前端 未结 7 1917
暗喜
暗喜 2020-12-13 17:53

I am sure there must be a relatively straightforward way to do this, but it is escaping me at the moment. Suppose I have a SQL table like this:

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


        
相关标签:
7条回答
  • 2020-12-13 18:36

    This should do it:

    SELECT A, B, COUNT(*) 
    FROM TableName
    GROUP BY A, B;
    
    0 讨论(0)
  • 2020-12-13 18:45

    SELECT A, B, COUNT(*) FROM MyTable GROUP BY A, B

    0 讨论(0)
  • 2020-12-13 18:48
    SELECT A,B,COUNT(*)
    FROM table
    GROUP BY A,B
    
    0 讨论(0)
  • 2020-12-13 18:49
    SELECT A,B,COUNT(*)
    FROM the-table
    GROUP BY A,B
    
    0 讨论(0)
  • 2020-12-13 18:51

    TRY:

    SELECT
        A, B , COUNT(*)
        FROM YourTable
        GROUP BY A, B
    
    0 讨论(0)
  • 2020-12-13 18:51

    This could be the answer:

    SELECT a, b, COUNT(*) 
    FROM <your table name here> 
    GROUP BY a,b 
    ORDER BY 3 DESC;
    
    0 讨论(0)
提交回复
热议问题