--用临时表
select id=identity(int,1,1)
,字段1=cast(字段1 as varchar)
,字段2=cast(字段2 as varchar)
,字段3,字段4
into #t from 表--查询结果
select 字段1=case when b.id is null then '' else 字段1 end
,字段2=case when b.id is null then '' else 字段2 end
,字段3,字段4
from #t a left join(
select id=min(id) from #t group by 字段1,字段2
)b on a.id=b.id--删除临时表
drop table #t

解决方案 »

  1.   


    前台处理。SQL查询只需简单地写:
    select * from tablename
      

  2.   

    --测试--测试数据
    create table 表(字段1 int,字段2 int,字段3 varchar(10),字段4 varchar(10))
    insert 表 select 1,2,'ww','qq'
    union all select 1,2,'io','io'
    union all select 2,2,'yu','yu'
    union all select 2,2,'er','er'
    union all select 3,9,'ii','ii'
    union all select 3,9,'pp','pp'
    go--用临时表
    select id=identity(int,1,1)
    ,字段1=cast(字段1 as varchar)
    ,字段2=cast(字段2 as varchar)
    ,字段3,字段4
    into #t from 表--查询结果
    select 字段1=case when b.id is null then '' else 字段1 end
    ,字段2=case when b.id is null then '' else 字段2 end
    ,字段3,字段4
    from #t a left join(
    select id=min(id) from #t group by 字段1,字段2
    )b on a.id=b.id--删除临时表
    drop table #t
    go--删除测试
    drop table 表/*--测试结果
    字段1        字段2        字段3        字段4        
    ---------- ---------- ---------- ---------- 
    1          2          ww         qq
                          io         io
    2          2          yu         yu
                          er         er
    3          9          ii         ii
                          pp         pp(所影响的行数为 6 行)
    --*/