测试testAInsertProductSellDaily() 出现错误
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'o2o.tb_user_product_map.shop_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
### The error may involve com.fushan.o2o.dao.ProductSellDailyDao.insertProductSellDaily-Inline
### 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'),count(product_id) AS total FROM tb_user_product_map WHERE date_format(create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day) GROUP BY product_id)
### Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'o2o.tb_user_product_map.shop_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'o2o.tb_user_product_map.shop_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
<insert id="insertProductSellDaily" parameterType="com.fushan.o2o.entity.ProductSellDaily">
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'),count(product_id)
AS total FROM
tb_user_product_map
WHERE
date_format(create_time,'%Y-%m-%d') =
date_sub(curdate(),interval 1
day) GROUP BY product_id)
</insert>
<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>
正在回答
同学你好。报错信息显示:
大致意思是:
选择列表的表达式“2”不在GROUP BY子句中,并且包含未聚合的列“o2o.tb_user_product_map.shop_id”,该列在功能上不依赖GROUP BY子句中的列;这与sql_mode=only_full_GROUP_BY不兼容
这和MySQL的版本有关,同学的版本是开启了严格模式的。
对于GROUP BY聚合操作,如果在SELECT中的列,没有在GROUP BY中出现,也没有出现在聚合函数里面,那么这个SQL是不合法的,因为列不在GROUP BY从句中,也就是说查出来的列必须在group by后面出现。否则就会报错。
同学可以参考一下 第三阶段课程 MySQL基础之数据类型 http://class.imooc.com/course/888 的教辅 严格模式的关闭.pdf 将本地的数据库严格模式关闭后再试。
如果解答了同学的疑问,望采纳~
祝学习愉快~
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quartzConfiguration': Unsatisfied dependency expressed through field 'productSellDailyService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productSellDailyServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productSellDailyDao' defined in file [E:\maven\bs\o2o\target\classes\com\fushan\o2o\dao\ProductSellDailyDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/fushan/o2o/config/dao/SessionFactoryConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\maven\bs\o2o\target\classes\mapper\ShopAuthMapDao.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.imooc.o2o.entity.ShopAuthMap'. Cause: java.lang.ClassNotFoundException: Cannot find class: com.imooc.o2o.entity.ShopAuthMap
老师重启完 出现了这个错误
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星