我需要知道在这个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').
谢谢。
答案 0 :(得分:0)
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'))
答案 1 :(得分:0)
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')
)