新人菜鸡,请各位大佬帮忙。想了很久,看不出来这个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
使用mybatis进行多条UPDATE的时候,要在JDBC连接中设置&allowMultiQueries=true,否则会报语法错误。