日期:2014-05-17  浏览次数:20856 次

找出pp2表中num重复的记录
我写的是select * from pp2 where num> (select count(num) from pp2 group by num);


答案是select * from pp2 where number in(select num from  pp2 group by num having(count(num)>1)


能帮分析一下答案中的having 的作用吗,以及为什么我的是不是有问题

------解决方案--------------------
1.你的问题
select count(num) from pp2 group by num 可能会返回多个值吧??
你用num>去比较,它不知道比较哪个,所以会出错。。除非你加个any关键字,应该就对了。
select * from pp2 where num> any(select count(num) from pp2 group by num);

2.正确的sql
having是分组后过滤,having(count(num)>1意思就是找出num有重复的。。