请教一个问题,我有一张表,
字段   a , b ,ca字段无重复数据
b字段有重复数据,
c字段有重复数据,现在我想拿出全部表数据,把b字段有重复的只要一条,该怎么写SQL 语句呢

解决方案 »

  1.   

    select a,b,c from table group by a,b,c
      

  2.   

    就是这样一个模式a      b     c
    1      www   ....
    2      www   ....
    3      ddd   ....
    4      eee   ....最后形成这样一个形式
    1      www   ....
    3      ddd   ....
    4      eee   ....
      

  3.   

    select * from table where cast(a as char(2))+b in (select cast(a as char(2))+b from (select a=max(a), b from table group b))
      

  4.   

    select * from table where cast(a as char(20))+b in (select cast(a as char(20))+b from (select a=max(a), b from table group b))
      

  5.   

    declare @tab table(a varchar(10),b varchar(10),c varchar(10)) insert into @tab select '1','www','aa'
     union
     select '2','www','bb'
     union
     select '3','ddd','dd'
     union
     select '4','eee','ee'
     union
     select '5','www','cc'
     union  
     select  '6','eee','ee'

    select * from @tab select * from @tab a where a in (select top 1 a from @tab where b=a.b)
    结果:    
    (所影响的行数为 6 行)a          b          c          
    ---------- ---------- ---------- 
    1          www        aa
    2          www        bb
    3          ddd        dd
    4          eee        ee
    5          www        cc
    6          eee        ee(所影响的行数为 6 行)a          b          c          
    ---------- ---------- ---------- 
    1          www        aa
    3          ddd        dd
    4          eee        ee(所影响的行数为 3 行)
      

  6.   

    select * from table a
    where not exists(select 1 from table where a.b=b and a.a>a)
      

  7.   

    有一点不太对,a+b都是唯一的,因为a是个ID字段,都是唯一的