求大神,我想查询出一张表中某一个字段重复,并且另外一个字段不重复的记录,该怎么写SQL语句呢?

解决方案 »

  1.   


    select id, name from A
    where id in (select id from A group by id having count(id) >= 2) 
    and name in (select name from A group by name having count(name)=1)
     
      

  2.   

    select * from aa where id in (select id from aa group by id having count(*)>1)
    and (id,name) not in (select id,name from aa group by id,name having count(*)>1);
      

  3.   

    在同一张表中,查询相同字段的数据,而另外字段不同数据,对吗?
    select * from biao a ,biao b where a.id!=b.id and a.name=b.name;     
    name字段值相同,id字段值不同。
      

  4.   

    select * from table a ,table b
    where a.重复字段 = b.重复字段  and a.不重复字段 <> b.不重复字段 
      

  5.   

    select * from table t where not exists(select * from table where t.fb_name=fb_name and t.fb_id>fb_id) 重复数据随便取一条。
      

  6.   

    select * From tab t1 where exists (select 1 from tab t2 where t2.字段1 = t1.字段1 and t2.字段2 <> t1.字段2);
      

  7.   

    select * from table a ,table b
    where a.重复字段 = b.重复字段 and a.不重复字段 <> b.不重复字段