0

我需要知道我在这个 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').

谢谢你。

4

2 回答 2

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'))
于 2012-06-13T04:45:05.757 回答
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')
  )
于 2012-06-13T05:59:12.503 回答