sql语句update+set+select求助

jsp数据库处理中
String sql=“

update buffers set lastSuccess='1' where customMoney=(select currentMoney from clothes where cloId=?) and b.cloId=?
pstmt.setString(1,cloId);
pstmt.setString(2,cloId);
pstmt.executeUpdate();

";
此语句报错,到update()那就通不过了

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to 
use near 'lastSuccess='1' where b.customMoney=(select currentMoney from clothes where cloI' at line 1

1个回答

update的主干语句里面 就是update xxx set xxxx=? where xxxxxx
不会有update xxx set xxxx=? from的写法
所以你的语句 应该是
update buffers t set lastSuccess = '1' where exists (select t1.customMoney from (select top 1 * from buffers group by cloId having cloId=? ) t1 where t1.customMoney=t.customMoney and t1.cloId=t.cloId)

另外 你的子查询中的order by 是没意义的 可能会影响执行效率

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问