日期:2014-05-17 浏览次数:20590 次
create table A表(ITEM varchar(10))
insert into A表
select 'abc' union all
select 'abc' union all
select 'abc' union all
select 'abc' union all
select 'abc' union all
select 'abc' union all
select 'abc'
select ITEM,
identity(int,1,1) 'rn1',
0 'rn2'
into #t
from A表
update #t
set rn2=(rn1-1)/3
select max(case when (rn1-rn2*3)=1 then ITEM else '' end) 'ITEM1',
max(case when (rn1-rn2*3)=2 then ITEM else '' end) 'ITEM2',
max(case when (rn1-rn2*3)=3 then ITEM else '' end) 'ITEM3'
from #t
group by rn2
/*
ITEM1 ITEM2 ITEM3
---------- ---------- ----------
abc abc abc
abc abc abc