0

有人可以帮助我使用 mysql 查询以使用 mysql 在临时表中显示每个组的重复项吗

sqlfiddle http://sqlfiddle.com/#!2/d8c9c/17

桌子

TOWN    ID1
town1   1
town1   1
town1   4
town2   1
town2   5
town2   8
town3   1
town3   3
town3   3

所需结果

TOWN    ID1
town1   1
town1   1
town3   3
town3   3

我试过 SELECT * FROM Table1 group by TOWN,ID1 但这会删除重复项并显示非重复记录

4

2 回答 2

0
SELECT a.TOWN, a.ID1 FROM Table1 a JOIN
  (SELECT TOWN, ID1 FROM Table1 GROUP BY TOWN, ID1 HAVING COUNT(*) > 1) b 
ON a.TOWN = b.TOWN
AND a.ID1 = b.ID1
于 2013-09-26T14:36:49.577 回答
0

这是您要查找的查询

SELECT TOWN, ID1  FROM Table1 t WHERE ( SELECT COUNT(*) FROM Table1 WHERE TOWN = t.TOWN AND ID1 = t.ID1 ) > 1;
于 2013-09-26T12:44:17.493 回答