编号 名称 规格 明细
001  002  003  1
001  002  003  1
004  005  006  2
004  005  006  2
004  005  006  2结果编号 名称 规格 明细
001  002  003  1
               1
004  005  006  2
               2
               2

解决方案 »

  1.   

    select id=identity(int,1,1) * into # from 你的表
    select 
        编号=case when a.id =b.id then a.编号 else '' end,
        名称=case when a.id =b.id then a.名称 else '' end,
        规格=case when a.id =b.id then a.规格 else '' end,
        a.明细
    from # a, (
        select id=min(id),编号,名称,规格 from #
        group by 编号,名称,规格
    )b
    where a.编号=b.编号 and a.名称=b.名称 and a.规格=b.规格drop table #
      

  2.   

    -- 保证顺序
    select id=identity(int,1,1) * into # from 你的表
    order by 编号,名称,规格
    select 
        编号=case when a.id =b.id then a.编号 else '' end,
        名称=case when a.id =b.id then a.名称 else '' end,
        规格=case when a.id =b.id then a.规格 else '' end,
        a.明细
    from # a, (
        select id=min(id),编号,名称,规格 from #
        group by 编号,名称,规格
    )b
    where a.编号=b.编号 and a.名称=b.名称 and a.规格=b.规格
    order by a.id   -- 保证顺序
    drop table #
      

  3.   

    个人觉得这种东西用T-SQL处理没有意思, 应该考虑在程序中显示时去格式化.