我有两个表。.我想将表中的相同数据集复制到自身,但是在table2中,我想将table1中的id复制到table2 id2中。
Table1
id group account
------------------------------
101 massive balls
201 nip ripper
301 holy magnum
Table 2
id title amount id2
-------------------------------------
1 expense 100.00 101
2 local 50.00 201
3 depart 25.00 301
这是我已经做过的,但无法获取b.title和b.amount的值
INSERT INTO Table1
OUTPUT inserted.Id, B.title, B.amount
INTO Table2(id2, title, amount)
SELECT A.*,
B.title,
B.amount,
B.id2
FROM Table1 AS A
LEFT OUTER JOIN
(SELECT title,
amount,
id2
FROM Table2) AS B
ON A.id = B.id2
插入后表中的数据应该是这样的。表1和2中的数据相同,但只将表1的ID复制到表2的ID2
Table1
id group account
------------------------------
101 massive balls
201 nip ripper
301 holy magnum
302 massive balls
303 nip ripper
304 holy magnum
Table 2
id title amount id2
-------------------------------------
1 expense 100.00 101
2 local 50.00 201
3 depart 25.00 301
4 expense 100.00 302
5 local 50.00 303
6 depart 25.00 304