数据插入报错
### The error may exist in file [/Users/xiao_xiaoxiao/Desktop/javaweb/o2o2/target/classes/mapper/ProductSellDailyDao.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into tb_product_sell_daily(product_id,shop_id,create_time,total) ( select product_id,shop_id,date_format(create_time,'%Y-%m-%d'),0 as total from tb_product p where p.product_id not in ( select product_id from tb_product_sell_daily where date_format(create_time,'%Y-%m-%d')=date_sub(curdate(),interval 1 day) GROUP by product_id )
### 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 '' at line 11
; bad SQL grammar []; nested exception is 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 '' at line 11
正在回答
同学这里是不是少写了表的别名,并且后面多写了group by呢
同学可以参考一下老师的sql:
<insert id="insertDefaultProductSellDaily"> INSERT INTO tb_product_sell_daily(product_id,shop_id,create_time,total) ( SELECT p.product_id,p.shop_id,date_sub(curdate(),interval 1 day),0 AS total FROM tb_product p WHERE p.product_id not in (select product_id from tb_product_sell_daily where date_format(create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day)) ) </insert>
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星