日期:2014-05-17 浏览次数:20927 次
create table ( aa varchar2(20) primary key, bb varchar2(20), cc varchar2(20), ); insert into table select '001','小明','xiaoming@d.com' from dual union all select '010','小明','xiaoming@d.com' from dual union all select '002','小红','xiaohong@d.com' from dual union all select '022','小红','xiaohong@d.com' from dual union all select '301','小明','xiaoming@d.com' from dual
select distinct bb,cc from t;
------解决方案--------------------
WITH t AS ( select '001' a,'小明' b,'xiaoming@d.com' c from dual union all select '010','小明','xiaoming@d.com' from dual union all select '002','小红','xiaohong@d.com' from dual union all select '022','小红','xiaohong@d.com' from dual union all select '301','小明','xiaoming@d.com' from dual ) 1. SELECT distinct b,c from t; 2. SELECT MIN(b),MIN(c) FROM t GROUP BY b,c; 3. SELECT b,c FROM (SELECT b,c,row_number() over(PARTITION BY b,c ORDER BY b,c)rn FROM t) WHERE rn=1 --你自己挑吧!
------解决方案--------------------
select * from tab1 t where (t.bb, t.cc) in (select bb, cc from tab1 group by bb, cc having count(*) > 1) and rowid in (select min(rowid) from tab1 group by bb,cc having count(*) > 1);
------解决方案--------------------
实测成功:
create table T19 ( aa varchar2(20) primary key, bb varchar2(20), cc varchar2(20) ); insert into TABLE SELECT MAX(NAME), MAX(Email) FROM (select '001' ID, '小明' NAME,'xiaoming@d.com' Email from dual union all select '010' ID,'小明' NAME,'xiaoming@d.com' Email from dual union all select '002' ID,'小红' NAME,'xiaohong@d.com' Email from dual union all select '022' ID,'小红' NAME,'xiaohong@d.com' Email from dual union all select '301' ID,'小明' NAME,'xiaoming@d.com' Email from dual) GROUP BY NAME, Email;