>4 个网友回答:
好像楼上几个说的不太对,group by 字段1,字段2
后应该不会有count(1)>1的情况,这样写是字段1,字段2重复出现的数据而不是字段2重复出现的数据。
select distinct 字段2,count(1)
from table
group by 字段2
having count(1) >1
换个思路,其实你就是要字段2里重复出现的数据,字段1只是一个附属产品,我这样写count(1)和count(字段2)是一个意思
编程论坛 5 个网友回答:
select t1.字段1,t1.字段2
from table t1,table t2
where t1.字段1 <> t2.字段1
and t1.字段2 = t2.字段2