select t1.id , isnull(t1.列1 , '') 列1 , isnull(t1.列2,'') 列2 , isnull(t2.列3 , '') 列3 , isnull(t2.列4,'') 列4 , isnull(t3.列5 , '') 列5 , isnull(t3.列6,'') 列6 from
(
select id , 列1 = 'A01' , 列2 = A01 from 表1
union all
select id , 列1 = 'A02' , 列2 = A02 from 表1
...
select id , 列1 = 'A0m' , 列2 = A0m from 表1
) t1
full join
(
select id , 列3 = 'B01' , 列4 = A01 from 表1
union all
select id , 列3 = 'B02' , 列4 = A02 from 表1
...
select id , 列3 = 'B0n' , 列4 = A0m from 表1
) t2 on t1.id = t2.id
full join
(
select id , 列5 = 'C01' , 列6 = C01 from 表1
union all
select id , 列5 = 'C02' , 列6 = C02 from 表1
...
select id , 列5 = 'C0x' , 列6 = C0x from 表1
) t3 on t1.id = t3.id其余的类似的写完。
(
select id , 列1 = 'A01' , 列2 = A01 from 表1
union all
select id , 列1 = 'A02' , 列2 = A02 from 表1
...
select id , 列1 = 'A0m' , 列2 = A0m from 表1
) t1
full join
(
select id , 列3 = 'B01' , 列4 = A01 from 表1
union all
select id , 列3 = 'B02' , 列4 = A02 from 表1
...
select id , 列3 = 'B0n' , 列4 = A0m from 表1
) t2 on t1.id = t2.id
full join
(
select id , 列5 = 'C01' , 列6 = C01 from 表1
union all
select id , 列5 = 'C02' , 列6 = C02 from 表1
...
select id , 列5 = 'C0x' , 列6 = C0x from 表1
) t3 on t1.id = t3.id其余的类似的写完。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货