兮之~ 2019-04-08 18:55 采纳率: 0%
浏览 797

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

  • 写回答

2条回答 默认 最新

  • interesting_star 2019-04-08 19:26
    关注

    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 是没意义的 可能会影响执行效率

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?