SQL update多个表出现语法错误?

新人菜鸡,请各位大佬帮忙。想了很久,看不出来这个SQL哪儿错了呀。

insert into ebook_snapshot(ebook_id, `date`, view_count, vote_count, view_increase, vote_increase)
        select t1.id, curdate(), 0, 0, 0, 0
        from ebook t1
        where not exists(select 1
                         from ebook_snapshot t2
                         where t1.id = t2.ebook_id
                           and t2.`date` = curdate());

        update ebook_snapshot t1, ebook t2
        set t1.view_count = t2.view_count,
            t1.vote_count = t2.vote_count
        where t1.`date` = curdate()
          and t1.ebook_id = t2.id;

SpringBoot的定时任务,更新两个表的数据,一直在疯狂报错。信息如下:

00.947 ERROR o.s.s.s.TaskUtils$LoggingErrorHandler:95   scheduling-1 218646970582044672 Unexpected error occurred in scheduled task
org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: 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 'update ebook_snapshot t1, ebook t2
        set t1.view_count = t2.view_count,
  ' at line 9
阅读 2.3k
1 个回答

使用mybatis进行多条UPDATE的时候,要在JDBC连接中设置&allowMultiQueries=true,否则会报语法错误。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题