有人可以使用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
我已经通过TOWN,ID1尝试了SELECT * FROM Table1组 但这会删除重复项并显示非重复记录
答案 0 :(得分:0)
这是您正在寻找的查询
SELECT TOWN, ID1 FROM Table1 t WHERE ( SELECT COUNT(*) FROM Table1 WHERE TOWN = t.TOWN AND ID1 = t.ID1 ) > 1;
答案 1 :(得分: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