日期:2014-05-18  浏览次数:20540 次

隐藏相同的同段名
名称 XXX
 A 100
 A 200
 C 200
 d 100
 A 500
 C 200


隐藏相同的同段名

名称 XXX
 A 100
  200
  500 
 C 200
  200 
 d 100

 

------解决方案--------------------
参考http://blog.csdn.net/geniuswjt/article/details/6739264
------解决方案--------------------
select (case when xxx = (select top 1 xxx from tb where 名称 = t.名称) then 名称 else '' end) 名称, xxx from tb t
------解决方案--------------------
http://blog.csdn.net/szstephenzhou/article/details/7110590
------解决方案--------------------
SQL code
if OBJECT_ID('tb') is not null  
drop table tb  
go  
create table tb (名称 varchar(50),XXX int)
insert into tb values('A',100)
insert into tb values('A',200)
insert into tb values('C',200)
insert into tb values('d',100)
insert into tb values('A',500)
insert into tb values('C',200)

select (case when xxx = (select top 1 xxx from tb where 名称 = t.名称) then 名称 else '' end) 名称, xxx from tb t
 
 名称                                                 xxx
-------------------------------------------------- -----------
A                                                  100
                                                   200
C                                                  200
d                                                  100
                                                   500
C                                                  200

(6 行受影响)

------解决方案--------------------
SQL code
if OBJECT_ID('tb') is not null  
drop table tb  
go  
create table tb (名称 varchar(50),XXX int)
insert into tb values('A',100)
insert into tb values('A',200)
insert into tb values('C',200)
insert into tb values('d',100)
insert into tb values('A',500)
insert into tb values('C',200)
 
select 名称=(case  when  rn=1 then  名称 else ''end  ),XXX
  from (select *,rn=ROW_NUMBER()over( partition by 名称 order by getdate()) from tb) t
  
   名称                                                 XXX
-------------------------------------------------- -----------
A                                                  100
                                                   200
                                                   500
C                                                  200
                                                   200
d                                                  100

(6 行受影响)