Mysql 更新:不能在FROM子句中为更新指定目标表“table”
我有两个关于oracle的问题。我需要为mysql修改它们。 第一个问题:Mysql 更新:不能在FROM子句中为更新指定目标表“table”,mysql,oracle,Mysql,Oracle,我有两个关于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); 我把它改成了 upd
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更改它,就像第一个查询一样,但它失败了,我不知道怎么做。提供您向我尝试的查询,第二个查询逻辑看起来与更新技术关闭文件没有什么不同,设置emailtype='REIN',其中transtype='REIN',emailtype为NULL或emailtype!='RENW.@Slowcoder也感谢您,您的查询更简单,并且给出的结果与来自草莓的查询相同。现在我知道了,我需要更多地了解sql。一个解释不会有什么坏处。@谢谢,它是有效的,但我不明白,为什么b.transtype为NULL?这是简单的排除连接。IS NULL语句只返回表的第一个实例中的行,第二个实例中没有对应的行。@草莓+1,谢谢您的帮助,我想我现在明白了。
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;