表:   
    
  字段1         字段2         字段3   
      1                 a                 900   
      2                 b                 800   
      3                 a                 700   
      4                 c                 600   
      5                 a                 900   
      6                 a                 600   
    
  如何才能筛选掉字段2重复记录?即:字段2 能否只显示出 a b c 

解决方案 »

  1.   


    --> 测试时间:2009-12-09 11:31:28
    --> 测试菜鸟:l8r
    --> 我的淘宝:《戒色坊》http://shop36766744.taobao.com/if object_id('[TB]') is not null drop table [TB]
    create table [TB]([字段1] int,[字段2] varchar(1),[字段3] int)
    insert [TB]
    select 1,'a',900 union all
    select 2,'b',800 union all
    select 3,'a',700 union all
    select 4,'c',600 union all
    select 5,'a',900 union all
    select 6,'a',600select * from [TB] t where not exists(select 1 from TB where t.字段2=字段2 and t.字段1>字段1)
    /*字段1         字段2  字段3         
    ----------- ---- ----------- 
    1           a    900
    2           b    800
    4           c    600(所影响的行数为 3 行)*/drop table [TB]
      

  2.   

    select 
      *
    from
     tb t
    where
     字段1=(select min(字段1) from tb where t.字段2=字段2)