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

问一条语句
表table1   有n个字段,a、b、c、d、e   等等,现在我要找出这样的数据来,
a         b       c       d         e
----------
1         r       u       t         k  
2         r       u       t         k
3         g       r       h         e
4         g       r       h         e


即b、c、d、e字段都有重复的,但a字段不重复的数据。不知道我说明白了没有。



------解决方案--------------------
select * from tbname a where (b,c,d,e) in(select b,c,d,e from tbname b group by b,c,d,e having count(*)> 1);
------解决方案--------------------
select a, b, c, d, e from
(select a, b, c, d, e, count(a)over(partition by b,c,d,e) num1, row_number(distinct a)over(partition by b,c,d,e,a order by a) num2 from tab_name )
where num1 > = 2
and num2 = 1