当前位置: 代码迷 >> Sql Server >> 反复的列值 ,只显示第一行,其他的显示为空
  详细解决方案

反复的列值 ,只显示第一行,其他的显示为空

热度:27   发布时间:2016-04-24 23:06:39.0
重复的列值 ,只显示第一行,其他的显示为空。
这样的一个数据的排列,
col1                col2               col3
1                    1                   2
1                    1                   3
1                    1                   4
2                    2                   5
2                    2                   6
2                    3                   7

显示成这样的
col1                col2               col3
1                    1                   2
                                         3
                                         4
2                    2                   5
                                         6
2                    3                   7
请教这语法?多谢!

------解决方案--------------------

select col1=(case when exists(select 1 from tb t2 where t1.col1=t2.col1 and t1.col2=t2.col2 and t1.col3>t2.col3) then '' else rtrim(col1) end),
col2=(case when exists(select 1 from tb t2 where t1.col1=t2.col1 and t1.col2=t2.col2 and t1.col3>t2.col3) then '' else rtrim(col2) end),col3 from tb t1
  相关解决方案