我有2个表的职业和级别。我要为同级别和相同的职业添加新的id。因此表中同时具有newid和oldid。但是现在我想创建一个包含该映射的映射表。 / p>
我有这个:
专业
id name country
1 doctor india
2 nurse india
11 doctor US
22 nurse US
我想要:
专业映射表
Oldid Newid
1 11
2 22
这与关卡表也是一样。
答案 0 :(得分:0)
假设oldid始终来自印度,newid始终来自美国,则可以根据名称并按国家/地区区分自己加入profession
表:
SELECT o.id AS oldid, n.id AS newid
INTO ProffesionMapping
FROM Proffesion o
JOIN Proffesion n ON o.name = n.name AND o.country = 'india' and n.country = 'US'
答案 1 :(得分:0)
那呢?
SELECT OLD.ID AS OLD_ID
, NEW.ID AS NEW_ID
INTO TBL_MAP
FROM
(
SELECT *
FROM TABLE_1
WHERE ID <= 2
) OLD
INNER JOIN
(
SELECT *
FROM TABLE_1
WHERE ID > 2
) NEW
ON OLD.NAME = NEW.NAME