我有两个关于 oracle 的查询。我需要为 mysql 修改它们。 第一个查询:
UPDATE tec_onoff_file a
SET emailtype = 'MIGR'
WHERE EXISTS
(SELECT 1
FROM tec_onoff_file
WHERE emailtype = 'MIGR'
AND a.acctnbr = acctnbr
AND a.magabbr = magcodes);
我把它改成了
update tec_onoff_file t1
join tec_onoff_file t2
on t2.emailtype='MIGR'
and t1.acctnbr=t2.acctnbr
and t1.magabbr=t2.magcodes
set t1.emailtype='MIGR';
并且它有效。 但第二个查询对我来说更难
update tec_onoff_file a
set emailtype = 'REIN'
where transtype = 'REIN'
and curracctnbr not in (select curracctnbr from tec_onoff_file b
where emailtype ='RENW'
and a.curracctnbr=b.curracctnbr);
有人可以帮忙吗?我正在尝试像第一次使用 JOIN 查询一样更改它,但它失败了,我不知道该怎么做。
最佳答案
UPDATE tec_onoff_file a
LEFT
JOIN tec_onoff_file n
ON b.curracctnbr = a.curracctnbr
AND b.emailtype ='RENW'
SET emailtype = 'REIN'
WHERE a.transtype = 'REIN'
AND b.transtype IS NULL;
关于mysql - 更新: You can't specify target table 'table' for update in FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26657375/