#创建test表
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`ID` int(11) default '0',
`name` varchar(255) NOT NULL default 'name'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
#添加模拟数据
INSERT INTO `test` VALUES (1,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (3,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (3,'name');
INSERT INTO `test` VALUES (5,'name');
INSERT INTO `test` VALUES (3,'name');
INSERT INTO `test` VALUES (2,'name');
INSERT INTO `test` VALUES (1,'name');
INSERT INTO `test` VALUES (1,'name');
#条件:查询ID重复条数>1的记录
#测试数据有十条,ID只有2和5不满足
#所以应该除了这两条记录都可以查询到
select test.* from test
inner join
(
select ID,count(*) num from test group by ID
) tmp
where test.ID = tmp.ID and tmp.num >1