日期:2014-05-19  浏览次数:20514 次

问一个简单语句
问一个语句       怎么把表tabl    
类型       客户
普通       张三
普通       李四
vip         王五
vip           赵六  

显示为    
类型     客户
普通       张三
              李四
vip         王五
              赵六

------解决方案--------------------
create table tabl(类型 varchar(10),客户 varchar(10))
insert into tabl
select '普通 ', '张三 '
union all select '普通 ', '李四 '
union all select 'vip ', '王五 '
union all select 'vip ', '赵六 '

select id=identity(int,1,1),* into #t from tabl
select case when 类型=(select top 1 类型 from #t a where a.id <#t.id order by a.id desc) then ' ' else 类型 end '类型 ',客户
from #t
drop table #t
/*
类型 客户
---------- ----------
普通 张三
李四
vip 王五
赵六

(所影响的行数为 4 行)
*/