[英]You can't specify target table 'b' for update in FROM clause
我需要知道在此sql語句中我在哪里做錯了。 我嘗試在類似問題的先前線程中找到解決方案,但沒有一個可以解決我的問題。 所以我認為也許我的陳述實際上是錯誤的。
UPDATE table1 b
LEFT JOIN table2 m ON b.ICNO=m.ICNO
SET b.SalMoveMth = '01'
WHERE
m.Status!='6' AND
(DATE_FORMAT(startDateSand,'%m')='10' OR DATE_FORMAT(startDateSand,'%m')='11' OR
DATE_FORMAT(startDateSand,'%m')='12') AND
((SELECT SalMoveMth FROM table1 WHERE ICNO=table2.ICNO ORDER BY SalMoveMthStDt DESC LIMIT 1)!='10').
謝謝。
where子句的最后一部分:
代替 :
where ICNO=table2.ICNO order by SalMoveMthStDt desc limit 1)!='10')
嘗試:
where ICNO=table2.ICNO order by SalMoveMthStDt desc limit 1)<>'10')
還:
and b.SalMoveMth in (
((select SalMoveMth from table1 where ICNO=table2.ICNO order by
SalMoveMthStDt desc limit 1)<>'10'))
update table1
set SalMoveMth = '01' where icno in
(select b.ICNO from table1 b
left join table2 m on b.ICNO=m.ICNO
where m.Status!='6'
and (DATE_FORMAT(startDateSand,'%m')='10' or
DATE_FORMAT(startDateSand,'%m')='11' or
DATE_FORMAT(startDateSand,'%m')='12')
and b.SalMoveMth in (
((select SalMoveMth
from table1
where ICNO=table2.ICNO
order by SalMoveMthStDt desc limit 1)<>'10')
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.