1

最初我必须从旧表中获取 ip 并将其放入电子邮件在两者中匹配的新表中。

INSERT INTO new (ip)
SELECT old.ip 
FROM old
INNER JOIN new on old.email = new.email;

我现在需要更改此查询以执行以下操作:

从旧表中获取 ip
匹配新表中该行的电子邮件 从新表中
获取 user_id
使用 user_id 和 ip 在组合表中创建记录

查询至今:

这很近吗?似乎不对:/

comb_uid = SELECT old.ip FROM old  
WHERE new.email = old.email

comb_ip = SELECT new.user_id FROM new  

INSERT INTO combined (user_id, ip)
VALUES comb_uid, comb_ip 
4

1 回答 1

0

你离得够近了。只需更改newcombined.

INSERT INTO combined (ip, user_ID)
SELECT  old.ip, new.user_ID
FROM    old
        INNER JOIN new 
            on old.email = new.email;

更新 1

INSERT INTO combined (ip, user_ID, status)
SELECT  old.ip, new.user_ID, 'approved'
FROM    old
        INNER JOIN new 
            on old.email = new.email;
于 2013-02-18T13:43:05.627 回答