我有一个数据表A里面有条数据(a1,10,a2,a3)4列 现在我想把这条数据放到B表中
在B表中的格式如下(号码,起点,数量,终点,主键2)像A中数据操作后应该有2条数据如下:
(1,a1,10,a2,A1)
(1,a2,10,a3,A2)
即A中一条数据在B中要有2条,a2既是终点也是起点 ,而且号码1要一致来说明它们是同一条数据。如何操作,拜托各位大虾了
在B表中的格式如下(号码,起点,数量,终点,主键2)像A中数据操作后应该有2条数据如下:
(1,a1,10,a2,A1)
(1,a2,10,a3,A2)
即A中一条数据在B中要有2条,a2既是终点也是起点 ,而且号码1要一致来说明它们是同一条数据。如何操作,拜托各位大虾了
insert tab
select 'a1',10,'a2','a3'select identity(int,1,1) AS ID
,tab.* into tab1 from tab
select * from tab1
select *,identity(int,1,1) AS tabID into tab2 from
(
select ID,起点,距离,中间 from tab1
union all
select ID,中间,距离,终点 from tab1
)A
select * from tab2
drop table tab,tab1,tab2
(1 行受影响)(1 行受影响)
ID 起点 距离 中间 终点
----------- ---------- ----------- ---------- ----------
1 a1 10 a2 a3(1 行受影响)(2 行受影响)ID 起点 距离 中间 tabID
----------- ---------- ----------- ---------- -----------
1 a1 10 a2 1
1 a2 10 a3 2(2 行受影响)