2012-06-27 35 views
0

在表中,我想根據三列和發現的重複計數返回重複行。基於3個匹配的列條目返回重複行的計數

例如, 在一行中,假設對於列a有一個1,對於列b有1,對於列c有1。 如果其他行的3列(1,1和1)具有完全相同的條目,我只想返回/計算此行。

在此先感謝! -N

+0

可能的重複問題:http://stackoverflow.com/questions/854128/find-duplicate-records-in-mysql – JohnP

回答

1
-- You need to specify the columns you need, and the count 
SELECT col1, col2, col3, COUNT(*) 
FROM  myTable 
-- Then you have to group the tuples based on the columns you are doing the count on 
GROUP BY col1, col2, col3 
-- Here you specify the condition for COUNT(*) 
HAVING COUNT(*) > 1; 

您可以找到有關這個here(加上其他一些有用的東西)的更多信息。