当前位置:网站首页>“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
2022-04-23 06:09:00 【qq_15197419】
问题描述
sql:
SELECT ID ,COUNT(ID) as favoriteCount,productID FROM l_favorite GROUP BY productID
报错:
MySql.Data.MySqlClient.MySqlException:“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘lec.l_favorite.ID’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”
原因分析:
一开始感觉比较奇怪,在数据库管理工具里运行不报错,EF又会报错。而且有时报错,有时又不报。
我先是直接搜索了报错内容,然后一堆文章直接就写的,去掉mysql配置文件里的sql_mode=ONLY_FULL_GROUP_BY配置。
就很无语,报错原因不说,也不解决问题,直接就去解决产生报错的配置项,既然默认配置是这样,那肯定有它的道理,不要动不动就去改配置,这不是好习惯。
然后翻译了下这段英文,大概意思是说ID这个字段没有聚合。
唔…看了下sql,自己马虎了,多select了个ID字段,而分组字段又是productID 。导致数据库认为,把多个不同的ID聚合成同一个ID,是不合法的。
解决方案:
把select后面没有聚合的ID字段去掉就行了。
版权声明
本文为[qq_15197419]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_15197419/article/details/123400712
边栏推荐
猜你喜欢
oracle通过触发器和序列来定义自增主键,并且设置定时任务每秒钟插入一条数据到目标表
AVD Pixel_2_API_24 is already running.If that is not the case, delete the files at C:\Users\admi
BottomSheetDialogFragment 与 ListView RecyclerView ScrollView 滑动冲突问题
Component learning (2) arouter principle learning
[2021 book recommendation] practical node red programming
Component based learning (3) path and group annotations in arouter
[recommendation for new books in 2021] professional azure SQL managed database administration
WebView displays a blank due to a certificate problem
补补网络缺口
【2021年新书推荐】Artificial Intelligence for IoT Cookbook
随机推荐
【2021年新书推荐】Kubernetes in Production Best Practices
Recyclerview 批量更新View:notifyItemRangeInserted、notifyItemRangeRemoved、notifyItemRangeChanged
Abnormal record-16
【2021年新书推荐】Practical IoT Hacking
oracle对表字段的修改
Antd Design Form表单检验
[2021 book recommendation] effortless app development with Oracle visual builder
[2021 book recommendation] artistic intelligence for IOT Cookbook
Google AdMob advertising learning
MySQL笔记5_操作数据
iTOP4412 SurfaceFlinger(4.4.4_r1)
Using queue to realize stack
开篇:双指针仪表盘的识别
ffmpeg常用命令
MySQL notes 4_ Primary key auto_increment
Component learning (2) arouter principle learning
组件化学习
JS 比较2个数组中不同的元素
MySQL notes 5_ Operation data
解决::Argument ‘radius‘ is required to be an integer