日期:2014-05-18 浏览次数:20337 次
declare @表1 table (ID int,A类型 varchar(2),B类型 varchar(2),C类型 varchar(2)) insert into @表1 select 1,'a1','b1','c1' union all select 2,'a2','b2','c2' union all select 3,'a3','b3','c3' ;with maco as ( select ID,A类型 from @表1 union select ID,B类型 from @表1 union select ID,C类型 from @表1 ) select id,char(64+row_number() over (partition by id order by a类型)) as 类型,A类型 from maco /* ID 类型 A类型 ----------- ---- ---- 1 A a1 1 B b1 1 C c1 2 A a2 2 B b2 2 C c2 3 A a3 3 B b3 3 C c3 */