如:表A,
a       b     c     d    
ems1    1     2     2
ems1    1     3     3
ems1    2     4     6
ems1    3     A     H
ems1    2     4     3
ems1    4     B     2查询表A,要求列出所有的列.执行2次查询,第1次是b列的数据不出现重复的;第2次是b列,d列的数据都不出现重复的.
请给出脚本,谢谢!!!

解决方案 »

  1.   

    select * from a a1
    where not exists (
    select b from
    where a2.b=a1.b
    group by b
    having count(*)=1
    )
    select * from a a1
    where not exists (
    select b,d from
    where a2.b=a1.b
    and a2.d=a1.d
    group by b,d
    having count(*)=1
    )
      

  2.   

    错了,改下select * from a a1
    where not exists (
    select b from
    where a2.b=a1.b
    group by b
    having count(*)>1
    )
    select * from a a1
    where not exists (
    select b,d from
    where a2.b=a1.b
    and a2.d=a1.d
    group by b,d
    having count(*)>1
    )
      

  3.   

    select * from A where b in 
    (select b from A group by b having count(b)=1);select * from A where b in 
    (select b from A group by b having count(*)=1) and d in
    (select d from A group by d having count(*)=1);
      

  4.   

    to:Yang_(扬帆破浪)  怎么a2都没有声明的,这样可以吗?
      

  5.   

    alter table A  add  ID int identity( 1,1)
      select a ,b, c ,d  from  A where  A.ID  in (select min(ID)ID from A group by b)
     select a ,b, c ,d  from A where  A.ID  in (select min(ID)ID from A group by b,d)
    alter table A drop coulumn  ID
      

  6.   


     Yang_(扬帆破浪) ( ) 信誉:132  2006-04-18 17:58:00  得分: 0  
     
     
       错了,改下select * from a a1
    where not exists (
    select b from a a2  --加表a别名a2
    where a2.b=a1.b
    group by b
    having count(*)>1
    )
    select * from a a1
    where not exists (
    select b,d from a a2  --加表a别名a2
    where a2.b=a1.b
    and a2.d=a1.d
    group by b,d
    having count(*)>1
    )