有2个表
=====================
A表:
业务种类名称 类别
------------------------
电信 缴费类
移动 缴费类
汽车票 票务类B表:
电信 移动 汽车票
-------------------------
232 34 72想要得到以下形式的表:
业务种类名称 类别
------------------------
电信 232
移动 34
汽车票 72
=====================
A表:
业务种类名称 类别
------------------------
电信 缴费类
移动 缴费类
汽车票 票务类B表:
电信 移动 汽车票
-------------------------
232 34 72想要得到以下形式的表:
业务种类名称 类别
------------------------
电信 232
移动 34
汽车票 72
连接查询,结果如下:declare @A表 table (业务种类名称 varchar(6),类别 varchar(6))
insert into @A表
select '电信','缴费类' union all
select '移动','缴费类' union all
select '汽车票','票务类'declare @B表 table (电信 int,移动 int,汽车票 int)
insert into @B表
select 232,34,72select aa.*,a.* from (
select '电信' as 业务种类名称 ,电信 from @B表 union all
select '移动' ,移动 from @B表 union all
select '汽车票' ,汽车票 from @B表
) aa left join
@A表 a on a.业务种类名称=aa.业务种类名称
/*
业务种类名称 电信 业务种类名称 类别
------ ----------- ------ ------
电信 232 电信 缴费类
移动 34 移动 缴费类
汽车票 72 汽车票 票务类
*/