数据插入报错

数据插入报错

### 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

http://img1.sycdn.imooc.com//climg/5d916ae4096d98a218140654.jpg

正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学这里是不是少写了表的别名,并且后面多写了group by呢

http://img1.sycdn.imooc.com//climg/5d91913709bec81415070385.jpg

同学可以参考一下老师的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>

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 肖小小 提问者 #1
    <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 tb.product_id from tb_product_sell_daily tb where date_format(tb.create_time,'%Y-%m-%d')=date_sub(curdate(),interval 1 day) ) </insert> ### SQL: 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 tb.product_id from tb_product_sell_daily tb where date_format(tb.create_time,'%Y-%m-%d')=date_sub(curdate(),interval 1 day) ) ### 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 10 ; 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 10 还是一样
    2019-10-01 15:50:05
好帮手慕柯南 2019-10-06 11:00:36

同学你好!

1.同学的sql在后面少写了一个括号呢

http://img1.sycdn.imooc.com//climg/5d9958d009a1eedc09380241.jpg

2.建议同学贴代码时在回答中贴出,回复中会改变代码的格式:

http://img1.sycdn.imooc.com//climg/5d9958ff09b521a811660184.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师