兮之~ 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 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员