方法一:可以通过group by 进行分组。
sql:select username,count(username) from tablename grop by username;
解释:以上sql就是通过分组函数读取出tablename表中username的值和每个不同值的统计个数。
方法二:可以通过distinct函数 进行去重查询。
sql:select distinct username from tablename
解释:本sql就是查询出所有的tablename表中的username值(不重复)。
SELECT ID FROM TABLE WHERE ID IN (SELECT ID FROM TABLE GROUP BY ID HAVING COUNT(ID) > 1)..一个表有多个字段也是类似的,至于不想显示count(*)去掉就可以了
select ID, COUNT(*) FROM TAB
GROUP BY ID
HAVING COUNT(*)>1
假如表名为t
select id from t where id in (select id from t group by id having count(id) > 1)