How to find duplicate count among several columns?

前端 未结 4 1023

Here is a sample table that mimics my scenario:

COL_1   COL_2   COL_3   COL_4   LAST_COL
A       P       X       NY      10
A       P       X       NY      11
A          


        
相关标签:
4条回答
  • 2021-01-21 09:57
    SELECT COL_1, COL_2, COL_3, COL_4, COUNT(*)
    FROM MyTable
    GROUP BY COL_1, COL_2, COL_3, COL_4
    

    If you ever want to weed out rows that don't have a duplicate:

    SELECT COL_1, COL_2, COL_3, COL_4, COUNT(*)
    FROM MyTable
    GROUP BY COL_1, COL_2, COL_3, COL_4
    HAVING COUNT(*) > 1
    
    0 讨论(0)
  • 2021-01-21 09:59

    If I am understanding correctly all you need is something like:

    SELECT COL_1,COL_2,COL_3,COL_4, COUNT(*) AS TOTAL
    FROM table
    GROUP BY COL_1,COL_2,COL_3,COL_4
    
    0 讨论(0)
  • 2021-01-21 10:00

    The GROUP BY is what you want here. For example:

    SELECT COL_1, COL_2, COL_3, COL_4, COUNT(*)
    FROM my_table
    GROUP BY COL_1, COL_2, COL_3, COL_4
    
    0 讨论(0)
  • 2021-01-21 10:03

    are having most number of rows

    So you want to count, and then ORDER BY the count DESC

    SELECT    COL_1, COL_2, COL_3, COL_4, COUNT(*) COUNT_ROWS
    FROM      TBL
    GROUP BY  COL_1, COL_2, COL_3, COL_4
    ORDER BY  COUNT_ROWS DESC
    
    0 讨论(0)
提交回复
热议问题