select (
         case when 字段2=(select top 1 字段2
                            from 表 
                               where 字段1=t.字段1 
                                 order by 字段2)
              then t.字段1
              else ''
         end
       )
       ,
       ,字段2from 表 t
order by 字段1,字段2--参考:
http://community.csdn.net/Expert/topic/4385/4385030.xml?temp=.7137415

解决方案 »

  1.   

    select (case when 字段2=(select top 1 字段2
                                from 表 
                                where 字段1=t.字段1 
                                order by 字段2)
                  then t.字段1
                  else ''
             end
           )
           ,字段2
    from 表 t
    order by 字段1,字段2
      

  2.   

    表的设计上有问题,如果出现空集,那么表中就存在了重复的数据,所以你必须建立一个标识列。
    [create] table #(col1 varchar(20),col2 varchar(20))
    insert into # values ('AA','200501')
    insert into # values ('AA','200502')
    insert into # values ('AA','200503')
    insert into # values ('BB','200501')
    insert into # values ('BB','200502')
    insert into # values ('BB','200503')
    insert into # values ('BB','200504')
    go
    alter table # add flag int
    go
    update # set flag=a.flag
    from (
    select *,flag=(select count(1) from (select col1 from # group by col1) a where a.col1<b.col1)
    from (select col1 from # group by col1) b) a,# b
    where a.col1=b.col1update # set col1 = ''
    from #
    where col2 not in (select min(col2) from # group by col1)select col1,col2 from #
    drop table #col1                 col2                 
    -------------------- -------------------- 
    AA                   200501
                         200502
                         200503
    BB                   200501
                         200502
                         200503
                         200504(所影响的行数为 7 行)