你这个就不好说, 如果name,id值都是一样的,直接 select distinct t.name,t.id from t_student t; 如果仅仅是name相同,而id不同的话,则不肯定实现你说的那种查询.因为根本不晓得两者取哪个?以上仅限我个人的意见??期待楼下良言...
示例如下: create table q( no varchar2(10), jg varchar2(10));insert into q values('q','10'); insert into q values('w','11'); insert into q values('e','10'); commit;找出jg重复的 select q1.* from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no NO JG ---------- ---------- e 10 q 10找出jg不重复的 select q.* from q where no not in (select q1.no from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no) NO JG ---------- ---------- w 11在JG重复的中找出rownum=1的,并且和jg不重复的合在一起 select q.* from q where no not in (select q1.no from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no) union select n,j from (select q1.no n,q1.jg j,rownum r from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no) where r=1 NO JG ---------- ---------- e 10 w 11
select mid(t.id),t.name from t_student t group by name;
select max(id) id,name from t_student group by name
如果name,id值都是一样的,直接
select distinct t.name,t.id from t_student t;
如果仅仅是name相同,而id不同的话,则不肯定实现你说的那种查询.因为根本不晓得两者取哪个?以上仅限我个人的意见??期待楼下良言...
create table q(
no varchar2(10),
jg varchar2(10));insert into q values('q','10');
insert into q values('w','11');
insert into q values('e','10');
commit;找出jg重复的
select q1.* from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no
NO JG
---------- ----------
e 10
q 10找出jg不重复的
select q.* from q where no not in (select q1.no from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no)
NO JG
---------- ----------
w 11在JG重复的中找出rownum=1的,并且和jg不重复的合在一起
select q.* from q where no not in (select q1.no from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no)
union
select n,j from (select q1.no n,q1.jg j,rownum r from q q1,q q2 where q1.jg=q2.jg and q1.no<>q2.no) where r=1
NO JG
---------- ----------
e 10
w 11