假设我有一个表A,里面30列,假设有个列叫Name,可重复出现,现在我要显示Name出现3次以上的数据显示出来(显示全部信息,也就是30列数据)怎么做?列少可以select Name from A having count(name)>3,但是我现在30列的话,总不能在group by里面把30列都弄进去吧?
1楼的2条语句都没有 DISTINCT 的作用.
SELECT * FROM TABLEA WHERE ID IN ( SELECT MAX(ID) FROM TABLEA GROUP BY ClassID HAVING COUNT(Name) > 3 )
SELECT * FROM TABLEA WHERE ID IN ( SELECT MAX(ID) FROM TABLEA GROUP BY Name HAVING COUNT(Name) > 3 )
上面那条GROUP BY 的字段应该是 Name
@咖菲猫: 大神,你能否先测试下?一条记录都出不来
select a.*
from a inner join (select Name from A group by Name having count(name)>3) b on a.name=b.name
或者
select a.*
from a where name in (select Name from A group by Name having count(name)>3)
大神,你能否先测试下?一条记录都出不来
@点燃寂寞青春:
select Name from A group by Name having count(name)>3这里面有数据的话,就不应该存在查不出来的。还有链接条件是不是name,这里只是给你一个提示,比如2楼说的,去重的问题,这里就没考虑。